Without Semaphore

Producer-Consumer Simulation

Producer

IDLE
1: while (true) {
2: item = produce()
3: wait(empty)
4: wait(mutex)
5: buffer[in] = item
6: in = (in + 1) % N
7: signal(mutex)
8: signal(full)
9: }
Items Produced
0
Step
0

Buffer

IN
OUT
[0]
[1]
[2]
Count
0
In Ptr
0
Out Ptr
0

Consumer

IDLE
1: while (true) {
2: wait(full)
3: wait(mutex)
4: item = buffer[out]
5: out = (out + 1) % N
6: signal(mutex)
7: signal(empty)
8: consume(item)
9: }
Items Consumed
0
Step
0

Synchronization Variables

Without synchronization - potential race conditions

count
0
in
0
out
0
bufferSize
3

Simulation Controls

Tip: Use Start to run the simulation automatically, or use Next/Previous for step-by-step execution. Watch how the semaphore values and buffer state change during execution.