# panic: sync: Once 被重复使用

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

## 根因

在 sync.Once 已被使用后再次尝试使用它，这是不允许的。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Use a flag with atomic operations to implement single execution: 

var done int32
go func() {
    if atomic.CompareAndSwapInt32(&done, 0, 1) {
        // do once
    }
}()
   ```
2. **** (85% 成功率)
   ```
   Ensure Once is used only once per lifecycle, and create a new instance if needed.
   ```

## 无效尝试

- **** — Copying a sync.Once is unsafe and can cause races; it's not designed to be copied. (90% 失败率)
- **** — If the Once is embedded in a struct that's reused, it may still be copied. (40% 失败率)
