# WARNING: DATA RACE
写操作 0x00c000... 由 goroutine 7 执行
先前的写操作 0x00c000... 由 goroutine 8 执行

- **ID:** `go/race-detector-write-write`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

两个 goroutine 在没有同步的情况下访问同一内存位置，且至少有一次写操作，在 -race 模式下被竞态检测器捕获。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   var mu sync.Mutex
mu.Lock()
counter++
mu.Unlock()
// or
atomic.AddInt64(&counter, 1)
   ```
2. **** (92% 成功率)
   ```
   results := make(chan int, len(items))
for _, it := range items {
    it := it
    go func(v int) { results <- compute(v) }(it)
}
   ```

## 无效尝试

- **** — The race is real; disabling detection does not fix corruption, which surfaces later as random crashes. (95% 失败率)
- **** — Sleep reduces the window but does not eliminate the race; the detector still reports it. (90% 失败率)
