# fatal error：并发 map 写入

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

## 根因

两个 goroutine 在无同步的情况下写入同一个 map。运行时检测到并发写并中止进程。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   var m sync.Map
m.Store(k, v)
v, ok := m.Load(k)
   ```
2. **** (96% 成功率)
   ```
   var mu sync.RWMutex
mu.Lock()
m[k] = v
mu.Unlock()
   ```

## 无效尝试

- **** — Other writes still race; the runtime aborts on the first detected concurrent pair. (90% 失败率)
- **** — Sleeps don't eliminate races under real load; the crash just becomes intermittent. (85% 失败率)
