我使用-race
go工具参数运行测试,输出
--- FAIL: TestRaceCondition (0.00s)
testing.go:853: race detected during execution of test
func TestRaceCondition(t *testing.T) {
var map sync.Map
for i := 0; i < 10; i++ {
go func() {
map.Store(strconv.Itoa(i),nil)
}()
}
}
我不明白,因为根据doc,
Map [...]可安全地被多个goroutine并发使用,而无需 额外的锁定或协调。