.
Similarly, you may ask, what is Pthread_cond_t?
DESCRIPTION. The pthread_cond_wait() and pthread_cond_timedwait() functions are used to block on a condition variable. They are called with mutex locked by the calling thread or undefined behaviour will result.
Subsequently, question is, why does Pthread_cond_wait need a mutex? The mutex is used to protect the condition variable itself. That's why you need it locked before you do a wait. Then when the condition variable is signalled or broadcast to, one or more of the threads on the waiting list will be woken up and the mutex will be magically locked again for that thread.
In this manner, how do you use condition variables?
In typical use, a condition expression is evaluated under the protection of a mutex lock. When the condition expression is false, the thread blocks on the condition variable. The condition variable is then signaled by another thread when it changes the condition value.
What is Pthread_mutex_t?
pthread_mutex_t is used to declare an object of type mutex. thus: pthread_mutex_t mymutexvariable; You would then use the mutex variable to lock and unlock a mutex.