GATE / CS ARCHIVE

GATE CSE 2020 / QUESTION 34

GATE CSE 2020 Q34

Operating Systems · Synchronization & Concurrency · Full GATE CSE 2020 paper

GATE 2020, Q34 2 marks · MCQ
Report issue

Synchronization & Concurrency

Question 34, GATE 2020: Each of n processes runs this once, with shared count=0, semaphores a=1,b=0, and P not using count:
P;
wait(a); count=count+1;
if(count==n) signal(b);
signal(a); wait(b); signal(b);
Q;
What is guaranteed? A no Q before all P finish; B at most two in Q; C P mutually exclusive; D at most n−1 in P.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Worked explanation

Before any process can signal b, some process must observe count=n while holding a. Since increments are protected and occur after P, count is exactly the number of completed P sections that have passed the increment. Thus the first b signal proves every P has completed. The subsequent wait(b);signal(b) passes a token along the waiting processes; it gates entry but does not keep b held during Q. A process may enter Q and another may immediately enter too, so no mutual-exclusion or two-process bound follows. P is outside both waits, so every process can be in P simultaneously. This is a one-use barrier, not a reusable barrier because count is never reset.

Derivation and answer

Semaphore a serializes count increments after each process finishes P. Semaphore b starts 0 and is signaled for the first time only when count=n, so no process can pass wait(b) before all have finished P. Each passing process signals b to release the next waiter. The signal occurs before Q, so Q is not mutually excluded or limited to two entrants. Thus this is a barrier, A.

Original paper, page 11 · Answer key