摘要: # 信号量可能在不同的领域中 对应不同的知识点 """ 互斥锁:一个厕所(一个坑位) 信号量:公共厕所(多个坑位) """ from threading import Semaphore,Thread import time import random sm = Semaphore(5) # 造了一个含有五个的坑位的公共厕所 def task(name): sm.acquire(... 阅读全文
posted @ 2019-08-14 20:28 小肥海 阅读(118) 评论(0) 推荐(0) 编辑
摘要: from threading import Event,Thread import time # 先生成一个event对象 e = Event() def light(): print('红灯正亮着') time.sleep(3) e.set() # 发信号 print('绿灯亮了') def car(name): print('%s正在等红灯'... 阅读全文
posted @ 2019-08-14 20:28 小肥海 阅读(91) 评论(0) 推荐(0) 编辑
摘要: from threading import Thread,Lock,current_thread,RLock import time """ Rlock可以被第一个抢到锁的人连续的acquire和release 每acquire一次锁身上的计数加1 每release一次锁身上的计数减1 只要锁的计数不为0 其他人都不能抢 """ # mutexA = Lock() # mutexB = Loc... 阅读全文
posted @ 2019-08-14 20:27 小肥海 阅读(106) 评论(0) 推荐(0) 编辑
摘要: """In CPython, the global interpreter lock, or GIL, is a mutex that prevents multiplenative threads from executing Python bytecodes at once. This lock 阅读全文
posted @ 2019-08-14 17:18 小肥海 阅读(137) 评论(0) 推荐(0) 编辑