乐趣区

关于python:python-中线程同步

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
退出移动版