go
runtime_error
ai_generated
true
WARNING: DATA RACE: Write by goroutine X, Read by goroutine Y (atomic variable)
ID: go/goroutine-atomic-load-store-mismatch
80%Fix Rate
86%Confidence
0Evidence
2025-08-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.4 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
Using atomic.Load/Store on a variable that is also accessed non-atomically, causing race.
generic中文
对同时被非原子访问的变量使用atomic.Load/Store,导致竞争。
Workarounds
-
95% success Use atomic operations consistently for all accesses
var val atomic.Value val.Store(42) v := val.Load().(int)
-
90% success Use sync.Mutex to protect all accesses
var mu sync.Mutex var x int mu.Lock() x = 42 mu.Unlock() mu.Lock() v := x mu.Unlock()
Dead Ends
Common approaches that don't work:
-
Using volatile keyword (not available in Go)
100% fail
Go doesn't have volatile; atomic operations are required.
-
Adding memory barrier manually
70% fail
Go's memory model is complex; manual barriers are error-prone.