rlock递归锁
Posted rongye
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rlock递归锁相关的知识,希望对你有一定的参考价值。
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递归锁的主要内容,如果未能解决你的问题,请参考以下文章
python基础 多线程threading join 守护线程setDeamon 递归锁Rlock