条件、事件、信号量本质上都是锁,不常用

"""
常用方法:
obj,acquire()
Obj.release()
obj.wait(),创建是阻塞状态,等待obj.notify()并且前后要有obj.acquire()和obj.release()
obj.notify(num),前后要有obj.acquire()和obj.release()
"""

 

# 线程 条件
from threading import Condition
from threading import Thread


def test(con):
    con.acquire()
    con.wait()
    print('Hello, World!')
  con.release()

con = Condition()
for i in range(10):
    Thread(target=test, args=(con, )).start()

con.acquire()
con.notify(2)
con.release()   # 注意运行完会发生阻塞

 

相关文章:

  • 2021-07-14
  • 2021-09-09
  • 2022-02-09
  • 2021-12-08
  • 2021-12-05
  • 2022-02-23
  • 2021-05-21
  • 2021-10-03
猜你喜欢
  • 2019-11-28
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2021-10-07
  • 2021-05-30
相关资源
相似解决方案