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

递归锁,死锁,使用递归锁解决死锁,信号量

递归锁

线程同步锁死锁递归锁信号量GIL

并发编程---死锁||递归锁---信号量---Event事件---定时器

python 多线程-01 锁