I will talk about some code because the explanation is simpler. Suppose mutexes are used correctly with condition variables so that they are simple:
while(1)
{
conditionVariable.wait();
}
while(1)
{
conditionVariable.notify_one();
}
while(1)
{
conditionVariable.notify_one();
}
What I would like to achieve is that stream 1 is expected to expect a condition variable when stream 2 or stream 3 is notified. As the code stands, there is a big gap between notify_one()
and wait()
in the form of some other code marked with comments. This gap means that it is sometimes called notify_one()
before it is possible to call wait()
.
, , notify_one()
wait()
( 1). , , (1 ) wait()
, Threads 2 3 notify_one()
, Thread 1 wait()
. , .
wait()
, , . , , wait()
, , . , .
: , 1 , 2 3 ?