map并发读写场景未加锁
package main
import "time"
func main() {
m := make(map[int]int)
go func() {
for i := 0; i < 10000; i++ {
m[0] = 1
}
}()
go func() {
for i := 0; i < 10000; i++ {
_ = m[0]
}
}()
time.Sleep(time.Second)
}
运行结果
go run加上race参数,输出存在data race的告警信息,只适用于运行时。
并发原语值拷贝
package main
import "sync"
func f(m sync.Mutex) {}
func main() {
var m sync.Mutex
f(m)
}
标签:10000,检测,sync,命令,func,time,go,main
From: https://www.cnblogs.com/WJQ2017/p/17064005.html