Properly handle pthread_cond_timedwait timing out