Waiting On A Condition Variable To wait on a condition variable, we use a combination of a mutex and a condition variable, and the "pthread_cond_wait" or "pthread_cond_timedwait" function. Lets see the waiting code, and then try to figure out what the heck this mutex is doing here. /* assume 'mutex' is an initialized mutes. */ /* assume 'cond' is an initialized cond. variable. */ /* must lock the mutex first. */ if (pthread_mutex_lock(&mutex) != 0) { /* handle error... */ } /* now wait on the condition */ /* mutex will be unlocked while we wait. */ if (pthread_cond_wait(&cond, &mutex) == 0) { /* condition was signaled. mutex is locked again. */ /* do your stuff... */ } /* finally, unlock the mutex. */ if (pthread_mutex_unlock(&mutex) != 0) { /* handle error... */ }