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.
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...
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.
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...