# 警告：数据竞争 - goroutine 6 在地址 0x00c000012345 写入

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

## 根因

并发读写共享变量而没有同步。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   var mu sync.Mutex
var x int
// Write
mu.Lock()
x = 1
mu.Unlock()
// Read
mu.Lock()
_ = x
mu.Unlock()
   ```
2. **** (90% 成功率)
   ```
   var x atomic.Int32
x.Store(1)
_ = x.Load()
   ```

## 无效尝试

- **** — Reads still race unless also atomic. (50% 失败率)
- **** — Go doesn't have volatile; no effect. (100% 失败率)
- **** — Sleep doesn't establish happens-before relationship. (90% 失败率)
