Conditional variables (Mutex)
A mutex may need special operations applied upon some condition being met. (For example processing a list when it is full.) To implement this we use data structure called conditional variable that holds at least:
Then an OS will offer 3 calls on the API:
- wait(mutex, condition): mutex is released and reacquired when the condition is met (i.e. they are notified about the condition).
- signal(condition): notify a single thread waiting on the condition it has been met.
- broadcast(condition): notify all threads waiting on the condition. (Though as they are all waiting on the mutex they only activate one at a time.)