# fatal error: 并发写入 map

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

## 根因

多个 goroutine 在无同步的情况下写入同一个 map，运行时检测到重叠写入并中止程序。

## 版本兼容性

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

## 解决方案

1. **** (94% 成功率)
   ```
   var mu sync.RWMutex
mu.Lock()
m[key] = value
mu.Unlock()
   ```
2. **** (90% 成功率)
   ```
   var m sync.Map
m.Store(key, value)
v, ok := m.Load(key)
   ```

## 无效尝试

- **** — The runtime detector may still fire and the race is not eliminated, only made less frequent. (80% 失败率)
- **** — Atomic values do not protect the map's internal buckets; the map itself is still raced. (70% 失败率)
