信号量,停车位限定数目锁

# 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()
posted @ 2019-02-20 02:08  ★小钻风★  阅读(111)  评论(0)    收藏  举报