码迷,mamicode.com
首页 > 其他好文 > 详细

04 信号量

时间:2019-01-14 15:55:56      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:target   lease   int   semaphore   tip   信号   其他   div   __name__   

import time
import random
from multiprocessing import Process,Semaphore

def f1(i,s):
    s.acquire()

    print(‘%s男嘉宾到了‘%i)
    time.sleep(random.randint(1,3))
    s.release()

if __name__ == ‘__main__‘:
    s = Semaphore(4)  #计数器4,acquire一次减一,为0 ,其他人等待,release加1,
    for i in range(10):
        p = Process(target=f1,args=(i,s))

        p.start()

  

04 信号量

标签:target   lease   int   semaphore   tip   信号   其他   div   __name__   

原文地址:https://www.cnblogs.com/work14/p/10267074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!