# WARNING: DATA RACE
Goroutine 7 在 0x00c0000b4010 处写入：

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

## 根因

两个 goroutine 并发访问同一内存位置，至少一个是写操作，且没有同步机制排序。仅在 -race 构建时被检测到；否则程序行为未定义。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Protect the shared variable with a mutex:

var mu sync.Mutex
mu.Lock()
counter++
mu.Unlock()
   ```
2. **** (92% 成功率)
   ```
   Use atomic operations for simple counters:

var counter int64
atomic.AddInt64(&counter, 1)
_ = atomic.LoadInt64(&counter)
   ```

## 无效尝试

- **** — Hiding the report does not fix the race; the bug persists and manifests as corrupted data or crashes in production. (95% 失败率)
- **** — Sleep reduces the probability but does not establish a happens-before relationship; the race and its undefined behavior remain. (90% 失败率)
