go
runtime_error
ai_generated
true
panic: 未持锁时调用 Cond.Broadcast
panic: sync: Cond.Broadcast called without lock held
ID: go/condition-broadcast-without-lock
80%修复率
87%置信度
0证据数
2024-10-09首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.20 | active | — | — | — |
| 1.22 | active | — | — | — |
根因分析
在未持有相关联的 Locker 的情况下调用 sync.Cond.Broadcast() 或 Signal(),违反了文档约定。
English
sync.Cond.Broadcast() or Signal() is called without holding the associated Locker, violating the documented contract.
解决方案
-
96% 成功率
c.L.Lock() // mutate predicate c.Broadcast() c.L.Unlock()
-
85% 成功率
close(done) // wakes all waiters without a Cond
无效尝试
常见但无效的做法:
-
85% 失败
Still not holding the lock when Broadcast executes; panic persists.
-
70% 失败
Burns CPU and reintroduces races on the shared predicate.