# 警告：数据竞争

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

## 根因

竞态检测器（go test -race / go run -race）观察到两个 goroutine 并发访问同一内存位置，至少一个是写操作，且没有同步。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   Introduce sync.Mutex or sync/atomic around the shared variable; ensure happens-before via channel send/receive.
   ```
2. **** (88% 成功率)
   ```
   Pass data by value into goroutines or use immutable snapshots; run go test -race in CI to prevent regressions.
   ```

## 无效尝试

- **** — The race still corrupts data in production; hiding it makes failures nondeterministic and worse. (95% 失败率)
- **** — Sleeps reduce detection probability but do not establish a happens-before relationship. (90% 失败率)
