Are you really allowed to call `pthread_cond_wait` without the mutex held?  http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_cond_wait.html says

> The pthread_cond_wait() and pthread_cond_timedwait() functions are used to block on a condition variable. They are called with mutex locked by the calling thread or undefined behaviour will result.