# 致命错误：所有 goroutine 都在休眠 - 死锁！（主函数未等待就退出）

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

## 根因

主函数退出时其他 goroutine 仍在运行，但它们阻塞在通道或其他操作上，导致死锁检测。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Use sync.WaitGroup to wait for all goroutines to finish before returning from main.
   ```
2. **** (90% 成功率)
   ```
   Use a done channel and close it when all work is done; main blocks on <-done.
   ```

## 无效尝试

- **** — Sleep is nondeterministic; goroutines may finish later or never, and it's inefficient. (70% 失败率)
- **** — Program exits prematurely, possibly leaving resources unclean or missing results. (90% 失败率)
