OS Concepts · Chapter 6

Process Synchronization Lab

Seven standalone pages covering the chapter's synchronization primitives and classic problems. Each page animates a deterministic, textbook-accurate trace frame by frame — press Play to watch processes race, wait, block and wake up.

The problem

Race Condition

An unsynchronized counter++ / counter-- loses an update. Toggle between the unsafe interleaving and the safe, serialized version.

Motivation
Software solution

Peterson's Solution

Two flags and a turn variable give mutual exclusion and bounded waiting with no hardware support at all.

flag[] · turn
Hardware solution

Synchronization Hardware

An atomic TestAndSet instruction builds a spinlock — simple, but costs CPU cycles while busy-waiting.

TestAndSet
Abstraction

Semaphores

A counting semaphore with wait()/signal() and a real waiting list — no busy-waiting, processes block and get woken.

wait · signal
Classic problem

Bounded-Buffer

Producer and Consumer share a circular buffer, synchronized with mutex, full and empty semaphores.

Producer–Consumer
Classic problem

Readers-Writers

Any number of readers may read concurrently; a writer needs the data set all to itself.

readcount · wrt
Classic problem

Dining Philosophers

Five philosophers, five chopsticks — watch the naive solution deadlock, then see the asymmetric fix avoid it.

Circular wait