rlock python
Python RLock.release()方法 (Python RLock.release() Method)
release() is an inbuilt method of the RLock class of the threading module in Python.
release()是Python中线程模块的RLock类的内置方法。
RLock class objects follow reentrancy. A reentrant lock must be released by the thread that acquired it. Once a thread has acquired a reentrant lock, the same thread may acquire it again without blocking; and the thread must release it once for each time it has acquired it. This method releases the lock, thereby decrementing the recursion level. If after the decreasing it becomes zero, then the lock is set to unlock, and if any other threads are blocked waiting for the lock to become unlocked, allow exactly one of them to proceed. If after the decreasing the recursion level is still nonzero, the lock remains locked and still owned by the calling thread.
RLock类对象遵循可重入性。 可重入锁必须由获取它的线程释放。 一旦线程获取了可重入锁,同一线程就可以再次获取它而不会阻塞; 并且线程必须在每次获取它后释放一次。 此方法释放锁定,从而降低递归级别。 如果在减小之后它变为零,则将锁设置为解锁,并且如果其他任何线程被阻塞以等待锁被解锁,则允许其中一个继续进行。 如果递归级别降低后仍不为零,则锁保持锁定状态,并仍归调用线程所有。
Module:
模块:
from threading import RLock
Syntax:
句法:
release()
Parameter(s):
参数:
None
没有
Return value:
返回值:
The return type of this method is <class 'NoneType'>. The method does not return anything. It releases the thread which had acquired it and decreasing the recursion level of the locked thread. If the level becomes zero, it is unlocked by the thread, and if the level is still nonzero, it is owned by the calling thread only.
此方法的返回类型为<class'NoneType'> 。 该方法不返回任何内容。 它释放获取它的线程并降低锁定线程的递归级别。 如果级别变为零,则由线程将其解锁,如果级别仍为非零,则仅由调用线程拥有。
Example:
例:
# program to illustrate the use of
# release() method in RLock class
# importing the module
import threading
# initializing the shared resource
x = 0
# creating an RLock object
rlock = threading.RLock()
# Creating first thread
rlock.acquire()
x = x + 1
# the below thread is trying to access
# the shared resource
rlock.acquire()
x = x + 2
rlock.release()
rlock.release()
# Rlock released by both the threads
# displaying the value of shared resource
print("Displaying the final value of the shared resource x:", x)
Output
输出量
Displaying the final value of the shared resource x: 3
翻译自: https://www.includehelp.com/python/rlock-release-method-with-example.aspx
rlock python