知识卡片
等待原子解锁返回前重新加锁
调用Wait前持有c.L,它登记等待并原子释放锁,挂起后在返回前重新取得锁。典型结构是c.L.Lock(); for !condition() { c.Wait() }; /* 使用状态 */; c.L.Unlock()。被唤醒不等于状态仍满足,因为重新竞争时其他参与者可能先改变它;循环检查保护业务条件。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Go sync.Cond · 查看原书依据
Wait atomically unlocks c.L and suspends execution // of the calling goroutine. After later resuming execution, // Wait locks c.L before ret
参考来源
- 位置:《Go 语言高性能编程》第20章《Go sync.Cond》(来源项目book-sources;源文件:extracted/Go 语言高性能编程/_epub-src/OEBPS/Text/20.html)
- 结论依据:调用Wait前持有c.L,它登记等待并原子释放锁,挂起后在返回前重新取得锁。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:Wait atomically unlocks c.L and suspends execution // of the calling goroutine. After later resuming execution, // Wait locks c.L before ret