A bit of confusion! What could be the problem if we look at the following scenario: My objective is to understand the mixture of condition variable with mutex.
T1
- LOCK { MUTEX }
- CHECK VARIABLE
- IF NOT SET, WAIT ON CONDITION VARIABLE
- UNLOCK {MUTEX} GO TO 1
T2
- MODIFY VARIABLE;
- SIGNAL CONDITION VARIABLE
There could be race condition between step 2. and 3., hence we use MUTEX. What I do not understand is the underlying idea of cond var + mutex.