Condition variables and monitor protocols
Watch a thread sleep until a job arrives, lose a signal that comes at the wrong moment, and learn why a woken thread tests again in a loop. Threads and concurrency contracts · Operating systems.
A worker finds the queue empty and must sleep, but a job may arrive in the gap before it is asleep. How does a thread sleep without missing the news?
What you will learn
- Write the wait protocol with a mutex and a predicate
- Explain why a lost signal strands a sleeper
- Use a while loop and say when broadcast is needed
Lesson outline
- A worker with nothing to do
- Sleep and wake with a mutex
- The signal nobody hears
- Why the test sits in a loop
- One change, several waiters
18 minutes · 5 scenes · 0 predict checks · 9 quiz questions
The full lesson is available with Premium.