The GATE Grind

GATE 2010 CS (CS1) – Question 55

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

Binary semaphores S0,S1,S2 start at 1,0,0. Concurrent processes execute:

P0: while(true) { wait(S0); print("0"); signal(S1); signal(S2); }
P1: wait(S1); signal(S0);
P2: wait(S2); signal(S0);

How many times is zero printed?

  1. At least twice
  2. Exactly twice
  3. Exactly three times
  4. Exactly once

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (A) At least twice

Explanation

P0 prints once using the initial S0 token. P1 and P2 can each signal S0 once. If both signals occur before P0 next waits, their tokens coalesce because S0 is binary, allowing one further print. If P0 consumes between signals, it prints twice more. Therefore the possible counts are two or three, so only A is guaranteed.

More Concurrency and Synchronization questions

All Concurrency and Synchronization questions →