GATE 2015 CS (CS3) – Question 31
Shared varP,varQ start false. These loops deliberately put the critical sections INSIDE the while bodies. Which property holds?
Process X: Process Y:
while(true) { while(true) {
varP=true; varQ=true;
while(varQ==true) { while(varP==true) {
critical_section_X; critical_section_Y;
varP=false; varQ=false;
} }
} }Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (A) Prevents deadlock but fails mutual exclusion
Explanation
When both flags are true, both inner-loop conditions hold, so both processes can enter their critical sections simultaneously. Mutual exclusion therefore fails. The loops do not block entry while waiting for the other flag to clear; their bodies are the critical sections, so this construction has no mutual-wait deadlock. Thus A. An empty spin-loop would be a different program.