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

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论