# panic: sync: 在上一次 Wait 返回前复用了 WaitGroup

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

## 根因

在上一次 wg.Wait() 仍在进行时再次调用 wg.Add()。运行时会检测到这种并发复用。

## 版本兼容性

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

## 解决方案

1. **** (94% 成功率)
   ```
   var wg sync.WaitGroup
wg.Add(len(items))
for _, it := range items { go func(i int){ defer wg.Done(); process(i) }(it) }
wg.Wait()
   ```
2. **** (88% 成功率)
   ```
   done := make(chan struct{})
go func(){ wg.Wait(); close(done) }()
<-done
// safe to reuse
   ```

## 无效尝试

- **** — Timing-dependent; under load the Wait may still be in progress. (85% 失败率)
- **** — Couples unrelated batches and can deadlock when one batch never completes. (60% 失败率)
