go
runtime_error
ai_generated
true
fatal error: concurrent map writes
ID: go/map-concurrent-write
80%Fix Rate
90%Confidence
0Evidence
2024-04-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
Two or more goroutines write to the same map without synchronization. The runtime detects overlapping writes and aborts the program.
generic中文
多个 goroutine 在无同步的情况下写入同一个 map,运行时检测到重叠写入并中止程序。
Workarounds
-
94% success
var mu sync.RWMutex mu.Lock() m[key] = value mu.Unlock()
-
90% success
var m sync.Map m.Store(key, value) v, ok := m.Load(key)
Dead Ends
Common approaches that don't work:
-
80% fail
The runtime detector may still fire and the race is not eliminated, only made less frequent.
-
70% fail
Atomic values do not protect the map's internal buckets; the map itself is still raced.