# 致命错误：所有 goroutine 都在休眠 - 死锁！（循环等待）

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

## 根因

多个 goroutine 在相互等待对方的通道，形成无法解决的循环依赖。

## 版本兼容性

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

## 解决方案

1. **** (85% 成功率)
   ```
   select {
case v := <-ch1:
    fmt.Println(v)
case <-time.After(time.Second):
    fmt.Println("timeout")
}
   ```
2. **** (90% 成功率)
   ```
   type Coordinator struct {
    ch chan int
}

func (c *Coordinator) Run() {
    for v := range c.ch {
        go func(v int) {
            // process
        }(v)
    }
}
   ```

## 无效尝试

- **** — Buffering only delays the deadlock; it doesn't break the circular wait. (80% 失败率)
- **** — Sleeping doesn't guarantee the order; the race condition remains. (90% 失败率)
