亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

threadingtest - python threading中的lock rlock 為何rlock可以調用多次acquire
阿神
阿神 2017-04-18 10:31:29
0
2
689

在python的多線程中,使用threading中的lock rlock鎖, 為何rlock可以調用多次acquire,lock缺不能,lock調用多次而且會發(fā)生死鎖,rlock不會,求大神指點下

阿神
阿神

閉關修行中......

reply all(2)
黃舟

rlock is a reentrant lock. You can simply understand that it comes with a counter. Acquire has a counter of +1, and release has a counter of -1. Negative values ??are not allowed, otherwise an exception will occur.

Why do we do this? Because the application scenarios are different, a reentrant lock can call another method that requires the lock, but a non-reentrant lock cannot do this.

def fun1():
    rlock.acquire()
    fun2()
    rlock.release()

def fun2():
    rlock.acquire()
    rlock.release()
PHPzhong

The difference between lock and rlock is r:
reentrant, can be entered repeatedly. A thread can acquire the same rlock multiple times without being blocked. If a thread acquires rlock multiple times, it must release the same number of times before it can be released. rlock.

Lock is different. It can only be acquired once and cannot be acquired again before it is released.

For more information, please refer to this answer:
http://stackoverflow.com/ques...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template