# 警告：数据竞态
由 goroutine 7 在 0x00c0000b4010 处写入：
  main.main.func1()

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

## 根因

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

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   var mu sync.Mutex
mu.Lock()
counter++
mu.Unlock()
   ```
2. **** (90% 成功率)
   ```
   var counter int64
atomic.AddInt64(&counter, 1)
n := atomic.LoadInt64(&counter)
   ```

## 无效尝试

- **** — The race still exists in production and can cause corrupted data or crashes; the flag only hides detection. (95% 失败率)
- **** — Mixing atomic and non-atomic access to the same variable is itself a race and still flagged by the detector. (80% 失败率)
