The GATE Grind

GATE 2013 CS (CS1) – Question 44

Operating System · Concurrency and Synchronization · 2 marks · Multiple choice

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?

  1. −2
  2. −1
  3. 1
  4. 2

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.

More Concurrency and Synchronization questions

All Concurrency and Synchronization questions →