# panic: sync: WaitGroup 在之前的 Wait 返回前被重用

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

## 根因

在上一次 wg.Wait 返回之前又调用了 wg.Add，说明 WaitGroup 被并发重用。

## 版本兼容性

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

## 解决方案

1. **** (94% 成功率)
   ```
   for _, batch := range batches {
    var wg sync.WaitGroup
    for _, item := range batch {
        wg.Add(1)
        go func(i Item) { defer wg.Done(); work(i) }(item)
    }
    wg.Wait()
}
   ```
2. **** (90% 成功率)
   ```
   g := new(errgroup.Group)
for _, item := range batch {
    g.Go(func() error { return work(item) })
}
g.Wait()
   ```

## 无效尝试

- **** — Sleep cannot guarantee goroutine completion and reintroduces races. (80% 失败率)
- **** — Reassigning wg while goroutines hold a reference to the old one causes Done to target the wrong counter. (75% 失败率)
