# WARNING: DATA RACE
写入 0x00c0000b4010 由 goroutine 7：
  main.increment()
      /app/main.go:12 +0x44

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

## 根因

竞态检测器观察到对同一内存的未同步并发访问。常见于多 goroutine 访问的共享计数器、slice 或结构体字段。

## 版本兼容性

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

## 解决方案

1. **** (97% 成功率)
   ```
   var mu sync.Mutex
func inc() {
    mu.Lock()
    counter++
    mu.Unlock()
}
   ```
2. **** (95% 成功率)
   ```
   var counter int64
atomic.AddInt64(&counter, 1)
   ```

## 无效尝试

- **** — The bug still exists; you just stop seeing reports while corrupt data and crashes continue. (95% 失败率)
- **** — Yielding does not provide memory ordering or mutual exclusion; races remain. (90% 失败率)
