some (tricky?) pthread_cond code