Bird
Raised Fist0

During execution of Peterson's algorithm, if process 0 sets its flag to true but process 1 never sets its flag, what happens when both try to enter the critical section?

medium🧠🧾 Concept Trace Q4 of Q15
Operating Systems - Critical Section Problem - Requirements & Peterson's Solution
During execution of Peterson's algorithm, if process 0 sets its flag to true but process 1 never sets its flag, what happens when both try to enter the critical section?
AProcess 0 enters the critical section immediately since process 1 is not interested
BProcess 0 waits indefinitely because process 1's flag is false
CBoth processes enter the critical section simultaneously causing a race condition
DProcess 1 enters the critical section first due to turn variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand flag usage in Peterson's algorithm

    A process sets its flag true to indicate interest in entering critical section.
  2. Step 2: Analyze scenario where process 1's flag is false

    If process 1's flag is false, it is not interested, so process 0 can enter immediately without waiting.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Only interested processes cause waiting; no interest means immediate entry [OK]
Quick Trick: Only processes with flag true cause waiting in Peterson's algorithm [OK]
Common Mistakes:
MISTAKES
  • Assuming process 0 waits regardless of process 1's flag
  • Thinking both enter simultaneously
Trap Explanation:
PITFALL
  • Candidates mistakenly believe process 0 must wait even if the other process is not interested, misunderstanding flag semantics.
Interviewer Note:
CONTEXT
  • Checks candidate's grasp of flag role in mutual exclusion logic.
Master "Critical Section Problem - Requirements & Peterson's Solution" in Operating Systems

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Operating Systems Quizzes