I am reading Python Threading Lock API.
Link here.
I am wondering what does the statement below mean.
"When the state is locked, acquire() blocks until a call to release() in another thread changes it to unlocked, then the acquire() call resets it to locked and returns."
I have read this statement 100 times. Still can't get it.
Why another thread to unlock? What does the statement after 'then' mean?
Is there any good explanation for this?
The overall meaning is that when a lock is acquired from a thread, other threads that call acquire waits untill the lock is released and lock it again:
When the state is locked,
Thread A acquire() the lock
acquire() blocks
Thread B try to acquire() the lock, but it is locked, so acquire() block current thread
until a call to release() in another thread changes it to unlocked
until the lock is released somewhere else (ie, it waits untill thread A release() the lock)
then the acquire() call resets it to locked and returns.
the acquire() of thread B locks the lock again
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With