The typical pattern I’ve seen for using pthread_cond_wait is:
pthread_mutex_lock(&lock);
while (!test)
pthread_cond_wait(&condition, &lock);
pthread_mutex_unlock(&lock);
Why can’t an if statement be used instead of a while loop.
pthread_mutex_lock(&lock);
if (!test)
pthread_cond_wait(&condition, &lock);
pthread_mutex_unlock(&lock);
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html
The
whileloop is a very standard way of re-evaluating the predicate, as required by POSIX.