OS Concepts · Chapter 6

Peterson's Solution

A software-only, two-process solution to the critical-section problem using two flags and a turn variable.

What's happening

P0 and P1 each raise a flag and politely yield the turn to the other. Whoever wrote turn last is guaranteed to wait — this gives both mutual exclusion and bounded waiting.

Shared state

Peterson's Solution

0 / 0
Speed
P0 critical section
—
P1 critical section
—

Event log