多线程共同操作同一个数据互斥锁同步?【面试题详解】

今天爱分享给大家带来多线程共同澡作同一个数据互斥锁同步?【面试题详解】,希望能够帮助到大家。



import threading
import time
class MyThread(threading.Thread):
    def run(self):
        global num
        time.sleep(1)

        if mutex.acquire(1):
            num +=1
            msg = self.name + 'set num to ' +str(num)
            print msg
            mutex.release()
num = 0
mutex = threading.Lock()
def test():
    for i in range(5):
        t = MyThread()
        t.start()
if __name__=="__main__":
    test()

原文链接:https://blog.itblood.com/4272.html,转载请注明出处。
0
收听节目Ep.9 AI版[PC+安卓/4.48G/更新]Tune in to the Show [Ep. 9] [精品SLG/汉化/动态]
收听节目Ep.9 AI版[PC+安卓/4.48G/更新]Tune in to the Show [Ep. 9] [精品SLG/汉化/动态]
10分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?