Wait until the protected condition changes
mtx_lock(&L->mtx); while (!L->finished && (L->accounted == L->iteration)) cnd_wait(&L->acco, &L->mtx); /* safely access protected state here */ mtx_unlock(&L->mtx); section 20.5
cnd_wait blocks the calling thread on a condition variable. The calling thread must already hold the supplied mutex. During the wait, cnd_wait temporarily releases that mutex so another thread can update the protected state and signal the condition variable; immediately before returning, it reacquires the mutex. section 20.5
Use cnd_wait with these synchronization rules:
- Protect the condition expression with the same mutex passed to cnd_wait. section 20.5
- Place the call inside a while loop and retest every part of the condition after it returns; an untimed wait may return early. section 20.5
- Use cnd_signal to wake one waiter or cnd_broadcast to wake all waiters associated with the condition variable. section 20.5
- Associate a condition variable with one mutex at a time, although several condition variables may share that mutex. section 20.5

