【发布时间】:2020-04-20 19:57:27
【问题描述】:
根据https://golang.org/pkg/sync/#Cond.Wait,必须将 Wait() 调用包装在 for 循环中,因为在第一次恢复时,c.L 据称未锁定。这和上面那句话“...,Wait locks c.L before return”相矛盾。
运行此code 时,即使 Wait() 在没有 for 循环的情况下立即恢复执行,也不会发生运行时错误,并且 Unlock() 应该在未先锁定而解锁时抛出运行时错误。
假设在 Go 中使用 Cond 时不需要 for 循环,因为在使用 Cond 时没有虚假唤醒,这是否正确?
【问题讨论】:
标签: go condition-variable