# fatal error: 所有 goroutine 都在休眠 - 死锁！（互斥锁加锁顺序）

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

## 根因

两个 goroutine 以相反顺序获取互斥锁 A 和 B，各自等待对方持有的锁。

## 版本兼容性

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

## 解决方案

1. **** (92% 成功率)
   ```
   // always lock A then B
muA.Lock()
defer muA.Unlock()
muB.Lock()
defer muB.Unlock()
   ```
2. **** (88% 成功率)
   ```
   var mu sync.Mutex
mu.Lock()
defer mu.Unlock()
// access both A and B
   ```

## 无效尝试

- **** — Busy retry burns CPU and does not guarantee progress; can still livelock. (70% 失败率)
- **** — Serializes everything, destroying concurrency, and may still deadlock with other lock paths. (60% 失败率)
