go
runtime_error
ai_generated
true
WARNING: DATA RACE
ID: go/race-detector-warning-data-race
80%Fix Rate
88%Confidence
0Evidence
2024-07-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
Two goroutines access the same memory location concurrently, at least one is a write, without synchronization. Detected by -race build.
generic中文
两个 goroutine 并发访问同一内存位置,至少一个是写操作,且没有同步。由 -race 构建检测。
Workarounds
-
95% success
var mu sync.Mutex mu.Lock() shared++ mu.Unlock()
-
92% success
var n int64 atomic.AddInt64(&n, 1)
Dead Ends
Common approaches that don't work:
-
90% fail
Hides the bug; corrupted state and crashes still occur in production.
-
80% fail
Go has no volatile; atomic fences alone don't fix logical races.