GATE / CS ARCHIVE

GATE CSE 1993 / QUESTION 22

Semaphore precedence implementation

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

GATE 1993, Q22 5 marks · Descriptive
Report issue

Synchronization & Concurrency

Question 22, GATE 1993: Implement DAG edges S1→S2,S1→S3,S2→S4,S2→S5,S3→S5,S6→S4,S6→S5 using parbegin/parend and semaphores. Note S6 is a source, not a sink.
Tap to enlarge
Answer & solution

Answer: One zero-initialized semaphore per edge; each task waits on incoming edges and signals outgoing edges. (no official key was published)

Use semaphores e12,e13,e24,e25,e35,e64,e65, each initialized to zero. P(e) waits and decrements atomically; V(e) signals. Run these six branches in one parbegin/parend block:

begin S1; V(e12); V(e13) end
begin P(e12); S2; V(e24); V(e25) end
begin P(e13); S3; V(e35) end
begin P(e24); P(e64); S4 end
begin P(e25); P(e35); P(e65); S5 end
begin S6; V(e64); V(e65) end

For each edge u→v, its semaphore can be signalled only after Su finishes, and Sv cannot start until its wait succeeds. Hence every required precedence is enforced. Distinct edge semaphores prevent one successor from consuming another's notification. They also allow a signal to arrive before its matching wait without being lost.

Only S1 and S6 have no predecessors, so they can begin concurrently. S4 awaits S2 and S6, while S5 awaits S2,S3,S6. In particular, the arrows drawn upward from S6 end at S4 and S5; reversing them would implement a different graph. No extra ordering is imposed between incomparable task executions, although a blocked wait can hold a branch until all its own predecessors finish. With terminating tasks and fair scheduling this acyclic dependency system has no synchronization deadlock.

Original paper, page 13