go
runtime_error
ai_generated
true
WARNING: DATA RACE Write at 0x00c0000b4010 by goroutine 5:
ID: go/race-detector-data-race
80%Fix Rate
90%Confidence
0Evidence
2024-02-28First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
| 1.23 | active | — | — | — |
Root Cause
Two goroutines access the same memory location without synchronization, and at least one is a write. Detected only when the binary is built with -race.
generic中文
两个 goroutine 在无同步的情况下访问同一内存位置,且至少一个是写操作。仅在以 -race 构建时被检测到。
Workarounds
-
95% success
var counter atomic.Int64 counter.Add(1) n := counter.Load()
-
92% success
ch := make(chan int) go func() { ch <- compute() }() result := <-ch
Dead Ends
Common approaches that don't work:
-
95% fail
Hides the symptom; the race still corrupts data nondeterministically.
-
90% fail
Yielding does not create a happens-before relationship; race remains.