首页 > 其他 > 详细

死锁现象

时间:2019-02-20 00:02:03      阅读:176      评论:0      收藏:0      [点我收藏+]
import threading
import time


lockA = threading.Lock()
lockB = threading.Lock()
class Mythread(threading.Thread):
def __init__(self,name):
super(Mythread,self).__init__()
self.name = name
def doA(self):
lockA.acquire()
print(self.name, "gotlockA", time.ctime())
time.sleep(3)
lockB.acquire()
print(self.name, "gotlockB", time.ctime())
lockB.release()
lockA.release()
def doB(self):
lockB.acquire()
print(self.name, "gotlockA", time.ctime())
time.sleep(3)
lockA.acquire()
print(self.name, "gotlockB", time.ctime())
lockA.release()
lockB.release()
def run(self):
self.doA()
self.doB()
if __name__ == ‘__main__‘:
t1 = Mythread("thread-1")
t2 = Mythread("thread-2")
t1.start()
t2.start()


解决办法:
threading.Lock() 改成threading.RLock

死锁现象

原文:https://www.cnblogs.com/knowlearner/p/10404099.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!