3个指针方法:git
Wait() 等待goroutine 等待接受通知,Single() Broadcast() 解除阻塞 Single() 发送通知,若是存在多个goroutine,只会任意选择一个 Broadcast() 广播 方法给全部人
下面时wait方法底层执行流程github
- 尝试解锁
- wait 尝试解锁,解完锁以后等待其余给发通知,===> 进入了阻塞状态,等待被唤醒: single(),broadcast()
- 一旦被唤醒后,又会锁定
func (c *Cond) Wait() { c.checker.check() t := runtime_notifyListAdd(&c.notify) c.L.Unlock() runtime_notifyListWait(&c.notify, t) c.L.Lock() }
操做案例:golang
sync.Cond