2) not deadlock, even with `critical_flag = TRUE` initially. It becomes a progress violation (indefinite postponement), which is a different liveness failure.
hypothetical
Initial state: `critical_flag = TRUE`, nobody has ever entered the CS.
Step Process Action Result
1 P1 `if (critical_flag == FALSE)` → FALSE skips CS, moves on
2 P2 `if (critical_flag == FALSE)` → FALSE skips CS, moves on
The flag is stuck at TRUE forever, because the only place it gets reset to FALSE is at the end of the critical region — and nobody ever reaches there. So no process can ever enter the CS.
Why this is NOT deadlock (check Coffman conditions)
Condition Holds here?
Mutual exclusion (vacuously) yes
Hold and wait ❌ No — nobody holds any resource while waiting
No preemption n/a
Circular wait ❌ No — P1 isn't waiting for P2, and P2 isn't waiting for P1
Two conditions fail ⇒ deadlock is impossible. Crucially: the processes are not blocked on each other — they're not even blocked at all. A failed `if` means skip and continue, not wait.
What it actually is
- Progress violated: no process is in the CS, processes want to enter, yet the "decision" of who enters is postponed indefinitely. Progress is one of the three required CS properties (mutual exclusion, progress, bounded waiting) — this construction kills it.
- If `get_exclusive_access()` is called in a loop, both processes keep testing and skipping forever — this is closer to starvation/livelock (active, but zero progress), still not deadlock.
Traps
- "Nobody ever enters" ≠ deadlock. Deadlock = a set of processes blocked, waiting for events only each other can trigger. Here the wait isn't on another process — it's on a flag nobody can reset. GATE marks these differently.
- Deadlock needs waiting — a plain `if` never waits. If the code had `while (critical_flag == TRUE);` instead, then your scenario would freeze both processes and the deadlock discussion would change.
- Note the original question initializes the flag to FALSE, so this stuck-TRUE state can't arise from the given code — it's purely a (valid) what-if.