# fatal error: 所有 goroutine 已休眠 - 死锁！（RWMutex 读等待写）

- **ID:** `go/deadlock-rwmutex-reader-writer`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

读持有 RLock 后试图获取写锁 Lock，或者递归 RLock 因已有写者排队而阻塞。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Never upgrade RLock to Lock; release the read lock before acquiring the write lock:

mu.RUnlock()
mu.Lock()
defer mu.Unlock()
   ```
2. **** (88% 成功率)
   ```
   Use a copy-on-write pattern with atomic.Pointer to avoid nested locks entirely.
   ```

## 无效尝试

- **** — Eliminates read concurrency but the nested-lock logic still deadlocks under the same call path. (80% 失败率)
- **** — The pending writer still blocks new readers; sleep merely reorders the deadlock. (85% 失败率)
