The thing is I've been using the lock statement to protect a critical part of my code, but now, I realize I could allow concurrent execution of that critical code is some conditions are met.
Is there a way to condition the lock?
Terms in an agreement prescribing for a time period within which any one of the contracting parties or either of the contracting parties cannot terminate the contract is known as a lock-in clause.
Creating and destroying condition variables A condition variable is created by calling the pthread_cond_init subroutine. You may specify a condition attributes object. If you specify a NULL pointer, the condition variable will have the default attributes.
Condition variables enable threads to atomically release a lock and enter the sleeping state. They can be used with critical sections or slim reader/writer (SRW) locks. Condition variables support operations that "wake one" or "wake all" waiting threads.
You can create a condition variable by calling lock. newCondtion() method. This class provides a method to wait on a condition and notify waiting for threads, much like the Object class' wait and notify method. Here instead of using wait() to wait on a condition, you call await() method.
I think that question cries "race condition!". What if the condition turns from true to false shortly after the check, but before a thread enters the critical section of code? Or while a thread is in the process of executing it?
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