Classical problems, traced
Bounded buffer and readers–writers step by step, with a quiz.
Module 3
Session 3.5
Lesson 1 of 2
Classical problems, traced
Bounded buffer and readers–writers — follow every semaphore value.
Bounded buffer: consumer arrives first
n = 3, consumer starts on an empty bufferStep through the interleaving one instruction at a time.
Readers–writers: a writer waits for two readers
First readers–writers solutionStep through the interleaving one instruction at a time.
Quick check
In the bounded buffer, what happens if the producer calls wait(mutex) before wait(empty) when the buffer is full?
It sleeps holding mutex; the consumer can never enter to free a slot.
In the first readers–writers solution, who may starve?
A continuous stream of readers keeps read_count above 0.
What is the purpose of the semaphore 'mutex' in the readers' code?
read_count++ and read_count-- are themselves critical sections.