go runtime_error ai_generated true

WARNING: DATA RACE

ID: go/race-detector-warning-data-race

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-07-14First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 95% success
    var mu sync.Mutex
    mu.Lock()
    shared++
    mu.Unlock()
  2. 92% success
    var n int64
    atomic.AddInt64(&n, 1)

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Hides the bug; corrupted state and crashes still occur in production.

  2. 80% fail

    Go has no volatile; atomic fences alone don't fix logical races.