Bird
Raised Fist0

If both processes simultaneously set their flags to true and set turn to the other process, what happens next in terms of entry to the critical section?

easy🧠🧾 Concept Trace Q12 of Q15
Operating Systems - Critical Section Problem - Requirements & Peterson's Solution
Consider two processes P0 and P1 using Peterson's algorithm. If both processes simultaneously set their flags to true and set turn to the other process, what happens next in terms of entry to the critical section?
ABoth processes enter the critical section simultaneously, causing a race condition
BThe process whose turn variable was set last enters the critical section first
COne process waits while the other enters the critical section, ensuring mutual exclusion
DBoth processes wait indefinitely, causing a deadlock
Step-by-Step Solution
  1. Step 1: Understand Peterson's turn variable role

    When both processes set their flags and turn, the turn variable decides who waits.
  2. Step 2: Mutual exclusion enforcement

    The process whose turn it is not will wait until the other finishes, ensuring only one enters the critical section.
  3. Step 3: Deadlock and race condition avoidance

    Peterson's algorithm prevents both deadlock and simultaneous entry.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Mutual exclusion is guaranteed by the turn variable and flags.
Quick Trick: Turn variable breaks ties, ensuring one process waits
Common Mistakes:
MISTAKES
  • Believing both can enter critical section simultaneously
  • Thinking the last to set turn always goes first
  • Assuming deadlock can occur here
Trap Explanation:
PITFALL
  • Option A is tempting if candidates ignore the turn variable's role. Option B confuses timing with logical control. Option D misinterprets waiting as deadlock.
Interviewer Note:
CONTEXT
  • Tests understanding of Peterson's algorithm's step-by-step synchronization 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