Semaphores can be thought of as extended mutexes that can have more than the two states - locked and unlocked.
Semaphores conceptually represent an abstract data type with two members:
- an integer
- a list of waiting threads (possibly empty)
Producer Consumer with a Bounded Buffer
A producer thread inserts items, one at a time, into a buffer of capicity B.
A consumer thread removes items, one at a time, from the same buffer.
The producer must block if the buffer is full.
The consumer must block if the buffer is empty.
The insert and remove operations may interfer with the buffer structure if allowed to be overlapped in execution.
Do we then also need mutual exclusion?