Condition

A condition variable allows one or more threads to wait until they are
notified by another thread.
If the lock argument is given and not None, it must be a Lock or RLock
object, and it is used as the underlying lock. Otherwise, a new RLock object
is created and used as the underlying lock.
  • 本质利用一个主锁, 加上N通知锁来实现
  • wait 步骤原理

    • 创建通知锁 锁定状态的lock1
    • 释放主锁
    • 堵塞lock1.acquire(),相当如等待解锁
    • lock1 解锁后, 锁定主锁
    • wait 结束,继续执行后续操作,并释放主锁;
  • 衍生出 Semaphore, Event

zed2015
15 声望2 粉丝