Chapter 6 · Simulation

Synchronization Lab

← Chapter 6
Mode
Procs 4
Capacity 2
Speed 1.5/s

Step 0/0 ✓ Inside 0 ⏸ Blocked 0

Synchronization Lab

Each process runs a small program made of wait/signal operations on semaphores. A round-robin scheduler lets the next unblocked process perform one operation per step, so you can watch who enters the critical section, who blocks in a semaphore’s FIFO queue, and who wakes whom. The panel on the right lists each process’s next operation and the latest events.

Usage

  • Pick a scenario: Mutex (shared counter), Semaphore (limited permits), Producer–Consumer (bounded buffer), Readers–Writers, or Dining Philosophers.
  • The controls on the second row change the option (locked or unlocked, which side is faster, ordered or naive fork picking), the number of processes (2–8) and the capacity (permits or buffer slots, 1–6).
  • ▶ plays; the step buttons move one operation back or forward, or jump to the start or end (up to 150 steps or until deadlock).
  • Compare runs the current scenario’s options side by side for 120 steps.

Operations

wait(S)
If S > 0, decrement it; otherwise block in S’s FIFO queue.
signal(S)
If someone is waiting, wake the first one (it receives the permit); otherwise increment S.
Scheduler
Round robin: the next unblocked process performs one operation.
Mutex
A binary semaphore wrapping the read → modify → write steps.
Race condition
No synchronization: two stale reads make one update get lost.
empty / full
Empty / full buffer slots.
rw_mutex
The first reader locks it, the last reader unlocks it; a writer must hold it alone.
Ordered forks
Picking the lower-numbered fork first breaks the circular wait.
Deadlock
All processes blocked: nobody can signal.

Legend

ready ✓ in critical section ⏸ blocked last to act

Keys

←→ stepSpace playHomeEndEsc close