# 致命错误：所有协程都处于休眠状态 - 死锁！

- **ID:** `go/goroutine-deadlock-all-goroutines-asleep`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

所有协程都在等待通道或锁，无法继续执行，通常是由于循环依赖或缺少发送/接收操作。

## 版本兼容性

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

## 解决方案

1. **Ensure each channel send has a corresponding receive in another goroutine** (99% 成功率)
   ```
   ch := make(chan int)
go func() {
    ch <- 1
}()
result := <-ch
   ```
2. **Use buffered channels to avoid blocking** (85% 成功率)
   ```
   ch := make(chan int, 1)
ch <- 1
// no receiver needed immediately
   ```

## 无效尝试

- **Adding more goroutines to break the deadlock** — More goroutines will also block if they follow the same pattern, exacerbating the issue. (95% 失败率)
- **Using time.Sleep to wait for conditions** — Sleep does not resolve the fundamental blocking; it only delays the deadlock detection. (90% 失败率)
