# 致命错误：并发读取和写入 map

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

## 根因

一个 goroutine 读取 map 的同时另一个 goroutine 写入该 map。运行时的 map 竞争检测器触发并导致进程崩溃。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Use sync.RWMutex: mu.RLock() for reads, mu.Lock() for writes; ensure reads also hold the lock
   ```
2. **** (85% 成功率)
   ```
   Pass map snapshots through channels so only one goroutine owns the map
   ```

## 无效尝试

- **** — Reads racing writes still trigger the fatal error (90% 失败率)
- **** — The copy itself iterates the map while it is being written, still racing (85% 失败率)
