# panic: sync: 在之前的 Wait 返回前复用了 WaitGroup

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

## 根因

在之前的 wg.Wait() 尚未返回时调用 wg.Add() 复用 WaitGroup。运行时检测到计数器被复用并 panic，以防静默计数错误。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Use a fresh WaitGroup per batch instead of reusing:
var wg sync.WaitGroup
for _, batch := range batches {
    wg = sync.WaitGroup{}
    // Add/Go/Wait for this batch
}
   ```
2. **** (85% 成功率)
   ```
   Ensure all goroutines have called Done before calling Add for the next round; synchronize rounds with a barrier channel.
   ```

## 无效尝试

- **** — The reuse still happens concurrently; the panic is about ordering, not the calling goroutine. (85% 失败率)
- **** — Copying a WaitGroup that has been used is unsafe and may race with the in-flight Wait. (80% 失败率)
