go golang 检测资源竞争

go run -race main.go

感觉不好用,不加锁会提示,加了锁还是会提示

var locks sync.Mutex

var iii int

func main() {

go func() {

for i := 0; i < 1000000; i++ {

locks.Lock()

iii++

locks.Unlock()

}

}()

for i := 0; i < 1000000; i++ {

locks.Lock()

iii++

locks.Unlock()

}

fmt.Println(iii)

}

你可能感兴趣的:(golang)