# 恐慌：同步：WaitGroup计数器为负

- **ID:** `go/waitgroup-negative-counter`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

调用Done()的次数多于Add()，导致WaitGroup计数器变为负数。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Ensure Add is called before starting goroutines and Done is called exactly once per goroutine.
   ```
2. **** (90% 成功率)
   ```
   Use a defer statement right after Add to guarantee Done is called.
   ```

## 无效尝试

- **** — The panic will crash the program; ignoring is not possible. (100% 失败率)
- **** — This masks the bug and may cause Wait() to return prematurely. (80% 失败率)
- **** — If Add is not called, Done will still decrement and may go negative. (70% 失败率)
