GATE 2013 CS (CS1) – Question 49
X computes a[i]=f(i), then ExitX(R,S), for i=0,…,n−1. Y calls EntryY(R,S), then computes b[i]=g(a[i]), for each i. R,S are binary semaphores initially zero. Which implementation correctly synchronizes the arrays?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (C) ExitX: P(S);V(R). EntryY: V(S);P(R).
Explanation
C implements a rendezvous: Y first signals S to announce readiness, then waits on R. X waits for that S signal after producing a[i], then signals R to release Y. Consequently no ready signal is lost through multiple increments of a binary semaphore, and Y consumes only produced elements. A initially deadlocks and B can lose signals if X outruns Y; D can similarly let binary signals coalesce. Thus C.