GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 21

Fork-join precedence graph

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

GATE 1996, Q21 5 marks · Descriptive
Report issue

Synchronization & Concurrency

Question 21, GATE 1996: fork L creates a new process starting at label L while the original continues. join V atomically decrements V and terminates the arriving process unless the new value is zero. For N=2; M=2; fork L3; fork L4; S1; L1: join N; S3; L2: join M; S5; goto next; L3: S2; goto L1; L4: S4; goto L2; next:, draw the precedence graph for S1..S5. The goto next after S5 is present in GFG but omitted in GateForum.
Question 21, GATE 1996: fork L creates a new process starting at label L while the original continues. join V atomically decrements V and terminates the arriving process unless the new value is zero. For N=2; M=2; fork L3; fork L4; S1; L1: join N; S3; L2: join M; S5; goto next; L3: S2; goto L1; L4: S4; goto L2; next:, draw the precedence graph for S1..S5. The goto next after S5 is present in GFG but omitted in GateForum.
Tap to enlarge
Answer & solution

Answer: Edges S1→S3, S2→S3, S3→S5, S4→S5 (no official key was published)

After the two forks there are three branches. The original executes S1, the L3 branch executes S2, and the L4 branch executes S4. There is no synchronization among those three statements, so they can occur in any order or overlap.

The S1 and S2 branches both reach join N. Because N starts at 2, the first arrival changes N to 1 and terminates; the second changes N to 0 and survives. Exactly one process therefore continues to S3, and S3 cannot start until both S1 and S2 have finished. This gives edges S1→S3 and S2→S3. The identity of the surviving process is irrelevant to the statement ordering.

The branch completing S3 and the branch completing S4 both reach join M. The same counting argument, with M initially 2, permits S5 exactly once, after both predecessors finish. Add edges S3→S5 and S4→S5. These four edges form the transitive reduction: draw S1 and S2 feeding S3, then S3 and S4 feeding S5. The additional transitive relations S1→S5 and S2→S5 need not be drawn.

This finite five-statement interpretation uses the paper's explicit goto next after S5. Its execution is not captured by the intended one-node-per-statement DAG. Omitting the jump is a material control-flow variant, not harmless punctuation.

Original paper, page 9