Bird
Raised Fist0

In Peterson's algorithm for two processes, if process 1 sets its flag to true and sets turn to process 0, while process 0 has its flag set to false, which process will enter the critical section first?

easy True/False Reasoning Q3 of Q15
Operating Systems - Critical Section Problem - Requirements & Peterson's Solution
In Peterson's algorithm for two processes, if process 1 sets its flag to true and sets turn to process 0, while process 0 has its flag set to false, which process will enter the critical section first?
ANeither process can enter the critical section
BProcess 0 enters the critical section first
CBoth processes enter simultaneously
DProcess 1 enters the critical section first
Step-by-Step Solution
Solution:
  1. Step 1: Analyze flags

    Process 1's flag is true, process 0's flag is false.
  2. Step 2: Check turn variable

    Turn is set to process 0, but since process 0's flag is false, it is not interested in entering.
  3. Step 3: Determine entry

    Process 1 will enter the critical section immediately because process 0 is not competing.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Only the process with flag true and no competing process enters [OK]
Quick Trick: Process with flag true and no competitor enters first [OK]
Common Mistakes:
MISTAKES
  • Assuming turn variable alone decides entry
  • Believing both processes enter simultaneously
  • Ignoring the flag status of processes
Trap Explanation:
PITFALL
  • Misinterpreting the turn variable as overriding the flag status
Interviewer Note:
CONTEXT
  • Tests understanding of flag and turn variables interaction in Peterson's algorithm
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