Producer–Consumer with Semaphores
Bounded buffer, empty/full counters and a mutex protect the shared queue.
Shared buffer (size 4)
emptyslot 0
emptyslot 1
emptyslot 2
emptyslot 3
Semaphores
empty
4
blocks producers when full
full
0
blocks consumers when empty
mutex
1
1 = unlocked, 0 = locked
Operation trace
Press Produce or Consume to see the semaphore operations step by step.
The empty/full semaphores enforce capacity, while mutex keeps the buffer update atomic. If a process blocks, try alternating producers and consumers to unblock it.