GATE / CS ARCHIVE

GATE CSE 2015 SET 3 / QUESTION 31

GATE CSE 2015 Set 3 Q31

Operating Systems · Synchronization & Concurrency · Full GATE CSE 2015 Set 3 paper

GATE 2015 Set 3, Q31 1 mark · MCQ
Report issue

Synchronization & Concurrency

Question 31, GATE 2015: Processes X and Y use shared Boolean flags varP and varQ, both initially false. Their synchronization pseudocode is:
X: while(true) { varP=true; while(varQ==true) { /* critical section X */ varP=false; } }
Y: while(true) { varQ=true; while(varP==true) { /* critical section Y */ varQ=false; } }
The critical sections are inside the inner while bodies, not after empty waiting loops. Which claim holds under the usual atomic-flag model? (A) prevents deadlock but fails mutual exclusion; (B) guarantees mutual exclusion but fails to prevent deadlock; (C) guarantees both; (D) guarantees neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Our answer: A under atomic shared-flag model

1. If both flags become true before either loop test, both processes can enter their critical sections, so mutual exclusion fails.

2. The inner loops are not waiting loops: their bodies execute the critical section when the other flag is true. Under fair execution and terminating critical sections, a false test returns to the outer loop and reasserts the flag; there is no state where both wait permanently for an action the other cannot perform. Thus A. Literal unsynchronized C threads would instead require a memory-model analysis; the source is treated as synchronization pseudocode.

Original paper, page 63 · Answer key