信号量,停车位限定数目锁
# project:pybuilder
# author:slx
# datetime:2019/2/20 1:23
# software: PyCharm
import time
import threading
class Mythread(threading.Thread):
# def __init__(self):
# super(Mythread,self).__init__()
def run(self):
if semaphore.acquire():
print(self.name)
time.sleep(3)
semaphore.release()
if __name__ == '__main__':
semaphore = threading.BoundedSemaphore(3)
thrs=[]
for i in range(23):
thrs.append(Mythread())
for t in thrs:
t.start()

浙公网安备 33010602011771号