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

RLock 解决死锁

时间:2019-02-20 10:06:06      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:elf   time()   name   import   time   sleep   threading   def   死锁   

import threading
import time

lock =threading.RLock()


class Mythread(threading.Thread):
def __init__(self,name):
super(Mythread,self).__init__()
self.name = name
def doA(self):
lock.acquire()
print(self.name, "gotlockA", time.ctime())
time.sleep(3)
lock.acquire()
print(self.name, "gotlockB", time.ctime())
lock.release()
lock.release()

def doB(self):
lock.acquire()
print(self.name, "gotlockA", time.ctime())
time.sleep(3)
lock.acquire()
print(self.name, "gotlockB", time.ctime())
lock.release()
lock.release()
def run(self):

self.doA()
self.doB()

if __name__ == ‘__main__‘:
t1 = Mythread("thread-1")
t2 = Mythread("thread-2")
t1.start()
t2.start()

RLock 解决死锁

标签:elf   time()   name   import   time   sleep   threading   def   死锁   

原文地址:https://www.cnblogs.com/knowlearner/p/10404321.html

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