Bugfix: correctly handle spurious wakeups in pthread_cond_timedwait