# fatal error: 并发 map 迭代和写入

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

## 根因

某 goroutine 使用 for range 迭代 map，同时另一 goroutine 向同一 map 写入，运行时检测到后直接终止。

## 版本兼容性

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

## 解决方案

1. **** (97% 成功率)
   ```
   mu.Lock()
for k, v := range m { process(k, v) }
mu.Unlock()
   ```
2. **** (93% 成功率)
   ```
   type req struct{ reply chan map[string]int }
for r := range reqs { r.reply <- snapshot(m) }
   ```

## 无效尝试

- **** — Copying without locking still races with the writer during the copy itself. (88% 失败率)
- **** — Taking the snapshot races with concurrent writes and can still trigger the detector. (86% 失败率)
