How does the conditional variable prevent the threads from continuously waiting for the thread?
This problem may have one or more correct answers
(a)The solution makes threads to check a condition and if that condition is true, then the threads go to sleep.
(b)When the threads go to sleep, they execute the wait() operation. wait() operation adds it to the wait queue until this thread is notified that the condition is false.
(c)When the thread using the lock releases it, then it notifies all the threads in the waiting queue.
(d)The next thread to acquire the lock should be the last one to enter the waiting queue.
Answers
answer:
a)The solution makes threads to check a condition and if that condition is true, then the threads go to sleep. When the threads go to sleep, they execute the wait() operation. ... When the thread using the lock releases it, then it notifies all the threads in the waiting queue.
b) - I dont know this one because im just In 8th grade
c) -
d) -
I am so so sorry I cant find more I m sorry I hope tis helps u
Answer:
wait() operation adds it to the wait queue until this thread is notified that condition is false. When the thread using the lock releases it, then it notifies all the threads in the waiting queue. The next thread to acquire the lock should be the last one to enter the waiting queue.
Explanation:
Condition variables: used to wait for a particular condition to become true (e.g. characters in buffer). wait(condition, lock): release lock, put thread to sleep until condition is signaled; when thread wakes up again, re-acquire lock before returning.
Condition variables are synchronization primitives that enable threads to wait until a particular condition occurs. ... Condition variables support operations that "wake one" or "wake all" waiting threads. After a thread is woken, it re-acquires the lock it released when the thread entered the sleeping state.
Condition Variable is a kind of Event used for signaling between two or more threads. One or more thread can wait on it to get signaled, while an another thread can signal this.
condition wait :=
The pthread_cond_wait() function atomically unlocks mutex and performs the wait for the condition. ... In this case, atomically means with respect to the mutex and the condition variable and another threads access to those objects through the pthread condition variable interfaces.