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

rlock递归锁

时间:2018-11-18 16:08:47      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:art   res   print   ase   turn   oba   one   递归   import   


import threading, time


def run1():
print("grab the first part data")
lock.acquire()
global num
num += 1
lock.release()
return num


def run2():
print("grab the second part data")
lock.acquire()
global num2
num2 += 1
lock.release()
return num2


def run3():
lock.acquire()
res = run1()
print(‘--------between run1 and run2-----‘)
res2 = run2()
lock.release()
print(res, res2)




num, num2 = 0, 0
lock = threading.RLock()
for i in range(1):
t = threading.Thread(target=run3)
t.start()

while threading.active_count() != 1:
print(threading.active_count())
else:
print(‘----all threads done---‘)
print(num, num2)

rlock递归锁

标签:art   res   print   ase   turn   oba   one   递归   import   

原文地址:https://www.cnblogs.com/rongye/p/9977959.html

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