OS Concepts · Chapter 6
A software-only, two-process solution to the critical-section problem using two flags and a turn variable.
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.