2-6.sync.Cond
结构体
type Cond struct {
noCopy noCopy // 用于保证结构体不会在编译期间拷贝
checker copyChecker // 用于禁止运行期间发生的拷贝
L Locker // 接口,需要实现 Lock 和 Unlock 方法,一般使用 Mutex 作为 Locker 即可
notify notifyList // 等待的协程链表
}
// 这个 wait 和 notify 字段是只增不减的,相当于自增ID。不是很理解为什么有链表了还需要索引
type notifyList struct {
wait uint32 // 正在等待的协程索引
notify uint32 // 已经通知到的协程索引
lock mutex
head *sudog
tail *sudog
}使用方法
接口
Wait()
Signal() 与 Broadcast()
小结
Last updated