golang sync.Mutex

rojas ·
例子换成 ```go package main import ( "fmt" "sync" "time" ) var l sync.Mutex var m *sync.Mutex func main() { m = new(sync.Mutex) go lock(1) go lock(2) time.Sleep(4 * time.Second) fmt.Printf("%s\n", "exit!") } func lock(i int) { println(i, "lock start") m.Lock() println(i, "lock") time.Sleep(2 * time.Second) m.Unlock() println(i, "unlock") } ``` 就更有说服力了
#1
更多评论
polaris
社区,需要你我一同完善!
#2