# fatal error: 并发读取和写入 map

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

## 根因

一个 goroutine 读取 map 的同时另一个 goroutine 写入该 map，且无同步，运行时检测到冲突并中止。

## 版本兼容性

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

## 解决方案

1. **** (94% 成功率)
   ```
   mu.RLock()
v := m[key]
mu.RUnlock()
   ```
2. **** (88% 成功率)
   ```
   type req struct{ key string; resp chan int }
for r := range reqs {
    r.resp <- m[r.key]
}
   ```

## 无效尝试

- **** — Copying itself iterates the map and races with concurrent writes, triggering the same fatal error. (75% 失败率)
- **** — Unlocked reads still race with locked writes; the detector fires on read/write overlap. (85% 失败率)
