# 致命错误：并发写入 map

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

## 根因

多个 goroutine 在无同步的情况下写入同一个 Go map。Go 运行时检测到并发写入后直接终止程序，无法通过 recover() 恢复。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   var mu sync.RWMutex; mu.Lock(); m[k]=v; mu.Unlock() — guard every access (read and write) with the same mutex
   ```
2. **** (90% 成功率)
   ```
   Use sync.Map for read-mostly or disjoint-key workloads: var m sync.Map; m.Store(k, v); m.Load(k)
   ```

## 无效尝试

- **** — fatal error is thrown by the runtime and bypasses the normal panic/recover mechanism entirely (95% 失败率)
- **** — Partial locking still leaves a write racing a read; the runtime still aborts (80% 失败率)
