A Real Condition For A Condition Variable (Cont.)
Scenario 2:
Thread S locks the mutex, the queue is empty.
Thread W tries to lock the mutex (which is locked) and blocks in "pthread_mutex_lock".
Thread S inserts an element to the queue.
Thread S signals the cond variable. no one is waiting on this var, and thus the signal is 'lost'.
Thread S unlocks the mutex.
Thread W now manages to lock the unlocked mutex.
Thread W checks the 'if' condition, and since the queue is not empty, it skips the checking of the condition variable.
Thread W extracts the element from the queue.
Thread W unlocks the mutex, and goes to handle the element.