Why do pthreads’ condition variable functions require a mutex?
问题 I’m reading up on pthread.h ; the condition variable related functions (like pthread_cond_wait(3) ) require a mutex as an argument. Why? As far as I can tell, I’m going to be creating a mutex just to use as that argument? What is that mutex supposed to do? 回答1: It's just the way that condition variables are (or were originally) implemented. The mutex is used to protect the condition variable itself . That's why you need it locked before you do a wait. The wait will "atomically" unlock the