...
Condition variables must be used inside a while
loop (see CON36-C. Wrap functions that can spuriously wake up in a loop for more information). To guarantee liveness, programs must test the while
loop condition before invoking the cnd_wait()
function. This early test checks whether another thread has already satisfied the condition predicate and has sent a notification. Invoking the cnd_wait()
function after the notification has been sent results in indefinite blocking.
...