The GATE Grind

GATE 2015 CS (CS3) – Question 31

Operating System · Concurrency and Synchronization · 1 mark · Multiple choice

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;
 }                             }
}                              }
  1. Prevents deadlock but fails mutual exclusion
  2. Guarantees mutual exclusion but can deadlock
  3. Guarantees mutual exclusion and prevents deadlock
  4. Can deadlock and fails mutual exclusion

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.

More Concurrency and Synchronization questions

All Concurrency and Synchronization questions →