GATE 2013 CS (CS1) – Question 44
x initially zero is shared by W,X,Y,Z. Each process waits on counting semaphore S=2, reads x, computes and stores its update, signals S and terminates. W,X increment by one; Y,Z decrement by two. What is the maximum final x?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (D) 2
Explanation
At most two processes can be inside, but their read-modify-write sequences are not atomic. Let W read zero and delay its write while Y and Z run sequentially through the other permit. W then writes one, overwriting their negative effects, and exits. X reads one and writes two. No increment chain can add more than two positive units, so maximum is 2, D.