Switch to pthread_mutex to implement _wait