go cond介绍,见:
https://studygolang.com/articles/25600?fr=sidebar
https://ieevee.com/tech/2019/06/15/cond.html
https://zhuanlan.zhihu.com/p/367166977
https://cyent.github.io/golang/goroutine/sync_cond/
其中,cond.Wait()方法是核心,个人对此方法理解是调用它时,会实际运行以下几步:
- 首先解锁(Unlock)。(这就是为何需要先加锁才能使用Wait()方法)
- 然后挂起调用者的goroutine阻塞,等待被Signal或者Broadcast唤醒
- 被唤醒,尝试加锁(Lock),若未能成功加锁将继续阻塞直到成功加锁
- 加锁成功,方法执行完毕
go的相关学习网站推荐:
https://cyent.github.io/golang/