package main
import (
"fmt"
"time"
)
var m = map[int]int{}
func main() {
m[1] = 1
m[2] = 2
go func() {
fmt.Println(m[1])
}()
go func() {
fmt.Println(m[1])
m[1] = 100
}()
time.Sleep(time.Second)
}
如上代码,运行时竟然是并发安全的(go run -race main.go得出的结论),很不解啊!!有没有大神解释下原因
[竞态监测器](https://blog.golang.org/race-detector) 中有这么一段话:
> Because of its design, the race detector can detect race conditions only when they are actually triggered by running code, which
means it's important to run race-enabled binaries under realistic workloads.
应该是说只有代码实际触发竞争条件才能检测到吧。
#2