# 致命错误: 并发遍历 map 与写 map

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

## 根因

一个 goroutine 用 range 遍历 map，同时另一个 goroutine 写入该 map，运行时将其视为致命竞争。

## 版本兼容性

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

## 解决方案

1. **** (93% 成功率)
   ```
   Hold an RWMutex read lock for the whole iteration and use a write lock for mutations.
   ```
2. **** (88% 成功率)
   ```
   Snapshot the map under a lock into a plain slice, then iterate the slice outside the lock.
   ```

## 无效尝试

- **** — The write still races with the copy loop and can panic during the copy itself. (70% 失败率)
