implementation of pthread_cond_timed_wait()