Overview:
- The release() method of the RLock class transitions an RLock object from locked state to unlocked state.
- Prior to calling release() if a thread has called acquire() “n” number of times, then release() must be called equal number of times to unlock the RLock object.
- After a call to acquire() method an Rlock object is in locked state and the thread called the acquire() method owns the lock. Only a thread that owns the RLock object can call the release() method. After release() the lock is not owned by any thread until the next acquire() method succeeds from one of the waiting threads.
- When the RLock object is in unlocked state calling release() will make Python to raise an Exception stating RuntimeError: cannot release un-acquired lock.
Example:
# Example Python program that uses the # Trivial definition of a shopping cart def addItem(self, item): def removeItem(self, item): def addRemoveItem(self, toAdd, toRemove):
# Create a reentrant lock # Add/remove items # Print the items |
Output:
<locked _thread.RLock object owner=8030314176 count=1 at 0x43f1c387b40> |