# 警告：数据竞争
写操作 0x... 由 goroutine 7 执行：
  main.main.func1()
      /main.go:12 +0x...
之前读操作 0x... 由主 goroutine 执行：
  main.main()
      /main.go:9 +0x...

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

## 根因

race 检测器（-race）发现 goroutine 之间对共享内存的未同步访问。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   var mu sync.Mutex
mu.Lock()
counter++
mu.Unlock()
   ```
2. **** (90% 成功率)
   ```
   results := make(chan int, 1)
go func() { results <- compute() }()
v := <-results
   ```

## 无效尝试

- **** — Hides the bug; production will still corrupt data. (95% 失败率)
- **** — Reduces but does not eliminate race; detector still flags it. (90% 失败率)
