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

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

## 根因

多个goroutine在没有同步的情况下并发访问map，导致运行时致命错误。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Use sync.RWMutex to protect reads and writes to the map.
   ```
2. **** (90% 成功率)
   ```
   Use sync.Map which is safe for concurrent use.
   ```

## 无效尝试

- **** — It can cause crashes or data corruption; ignoring is not safe. (90% 失败率)
- **** — If not all accesses are protected, the race can still occur. (40% 失败率)
- **** — Copying is expensive and does not solve the root race condition. (70% 失败率)
