Add some error checking to pthread_cond_wait