Skip to content

Commit 7d07ccb

Browse files
JesseJesse
authored andcommitted
point parameter
1 parent c97126f commit 7d07ccb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/defer/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"sync"
6+
"time"
7+
)
8+
9+
func main() {
10+
defer fmt.Println("1")
11+
defer fmt.Println("2")
12+
defer fmt.Println("3")
13+
loopFunc()
14+
time.Sleep(time.Second)
15+
}
16+
17+
func loopFunc() {
18+
lock := sync.Mutex{}
19+
for i := 0; i < 3; i++ {
20+
// go func(i int) {
21+
lock.Lock()
22+
defer lock.Unlock()
23+
fmt.Println("loopFunc:", i)
24+
// }(i)
25+
}
26+
}

0 commit comments

Comments
 (0)