# 致命错误：所有协程都在休眠 - 死锁！（无缓冲通道发送）

- **ID:** `go/goroutine-unbuffered-channel-blocking`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

无缓冲通道发送会阻塞直到有接收者就绪；如果没有接收者，协程会死锁。

## 版本兼容性

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

## 解决方案

1. **Use a buffered channel to allow sends without immediate receiver.** (95% 成功率)
   ```
   ch := make(chan int, 1)
ch <- 42 // non-blocking
val := <-ch
fmt.Println(val)
   ```
2. **Ensure a receiver goroutine is started before sending.** (100% 成功率)
   ```
   ch := make(chan int)
go func() {
    val := <-ch
    fmt.Println(val)
}()
ch <- 42 // now receiver is ready
   ```

## 无效尝试

- **Using a buffered channel but with size 0, which is unbuffered.** — make(chan int, 0) creates an unbuffered channel, still blocking. (90% 失败率)
- **Adding a receiver in the same goroutine after the send.** — The send blocks before the receiver is reached, causing deadlock. (100% 失败率)
