# 致命错误：并发映射写入

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

## 根因

多个 goroutine 在没有同步的情况下写入同一个映射会导致运行时崩溃。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   var mu sync.RWMutex
m := make(map[string]int)
// Write
mu.Lock()
m["key"] = 1
mu.Unlock()
// Read
mu.RLock()
val := m["key"]
mu.RUnlock()
   ```
2. **** (90% 成功率)
   ```
   var m sync.Map
m.Store("key", 1)
val, _ := m.Load("key")
   ```

## 无效尝试

- **** — Concurrency issue is not about collisions; it's about data races. (90% 失败率)
- **** — sync.Map is safe for concurrent writes, but if mixed with regular map, issue persists. (70% 失败率)
- **** — Sleeps don't synchronize; race remains. (95% 失败率)
