# 警告: 数据竞争
地址 0x00c0000... 的写入由 goroutine N 执行:

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

## 根因

两个 goroutine 并发访问同一内存位置，其中至少一个是写操作，且没有同步；在使用 -race 运行时被检测到。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.1+ | active | — | — |

## 解决方案

1. **** (93% 成功率)
   ```
   Protect the shared variable with sync/atomic:
atomic.AddInt64(&counter, 1)
v := atomic.LoadInt64(&counter)
   ```
2. **** (95% 成功率)
   ```
   Guard the critical section with a sync.Mutex and keep the section minimal.
   ```

## 无效尝试

- **** — Hides the symptom; the race still corrupts data in production and can cause random crashes. (90% 失败率)
- **** — Atomic on only one side does not establish a happens-before relationship; the race persists. (80% 失败率)
