Each process raises its flag to signal "I want to enter the critical section." Like raising your hand in class before speaking.
After flagging, a process politely says "you go first" by setting turn = j. This gift breaks ties and prevents deadlock.
Wait only when BOTH: other process wants in AND it is the other's turn. If either is false → enter immediately.
Click Step to advance one action at a time. Watch how flags and turn change. Auto-run simulates continuous interleaving.
Mutual Exclusion
Only one process can be in the critical section at any time. The turn variable ensures this — both can't win the coin flip.
Progress
If one process is not interested (flag[j] = false), the other enters immediately without waiting. No unnecessary blocking.
Bounded Waiting
After P0 exits and sets turn = 1, P1 is guaranteed entry on its next attempt. No starvation — each process waits at most one turn.