MCPcopy
hub / github.com/mao888/golang-guide / add

Function add

golang/go-study/go语言基础/并发/并发安全和锁/互斥锁/Mutex.go:18–25  ·  view source on GitHub ↗

add 对全局变量x执行5000次加1操作

()

Source from the content-addressed store, hash-verified

16
17// add 对全局变量x执行5000次加1操作
18func add() {
19 for i := 0; i < 5000; i++ {
20 mutex.Lock() // 修改x前加锁
21 x += 1
22 mutex.Unlock() // 改完解锁
23 }
24 wg.Done()
25}
26
27func main() {
28 wg.Add(2)

Callers 1

mainFunction · 0.70

Calls 1

DoneMethod · 0.80

Tested by

no test coverage detected