GATE / CS ARCHIVE

SIMILAR QUESTIONS / OPERATING SYSTEMS

Convert finite parallel code and precedence graphs

3 questions solved the same way, newest first. Back to Operating Systems

How these are solved

Recover statement predecessor edges from explicit finite parallel/serial or fork/join control, or construct equivalent structured code from the given DAG. Preserve fork/join count semantics and all directed branches; no shared-data race or semaphore ownership is inferred.

Descriptive
Report issue

Fork-join precedence program

Synchronization & Concurrency

Question 24(b), GATE 1998: Represent the graph with edges S1→S2,S1→S3,S1→S4,S1→S5,S2→S4,S4→S5,S3→S5 using parbegin/parend.
Question 24(b), GATE 1998: Represent the graph with edges S1→S2,S1→S3,S1→S4,S1→S5,S2→S4,S4→S5,S3→S5 using parbegin/parend.
Tap to enlarge
Answer & solution

Answer: S1; parbegin {S2;S4} || {S3} parend; S5. (no official key was published)

S1 must finish first. Afterward S3 can run independently of the chain S2 then S4. S5 must wait for both branches. A structured program is:

begin
  S1;
  parbegin
    begin
      S2;
      S4;
    end
    S3;
  parend;
  S5;
end

Here parbegin starts its two child statements concurrently, and parend joins them. The first child is a sequential block, so S2 precedes S4. The second child is S3. The final join guarantees both S3 and S4 finish before S5. Edges S1→S4 and S1→S5 are already implied by the paths through S2/S4, but are still satisfied. There is no imposed order between S3 and S2 or between S3 and S4, so the program preserves the graph's available parallelism rather than unnecessarily serializing it.

Original paper, page 8

5 marks · Descriptive
Report issue

Fork-join precedence graph

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

Descriptive
Report issue

Precedence graph for nested parallel blocks

Synchronization & Concurrency

Question 12(a), GATE 1992: Draw the precedence graph for this concurrent program. Within begin/end statements are sequential; parbegin/parend runs its components concurrently and joins them:
S1;
parbegin
  begin S2; S4 end;
  begin S3; parbegin S5; begin S6; S8 end parend end;
  S7
parend;
S9
Tap to enlarge
Answer & solution

Answer: Edges: 1→2,3,7; 2→4; 3→5,6; 6→8; 4,5,8,7→9. (no official key was published)

S1 executes before the outer fork. Its three branches start with S2, S3, and S7. In the first branch S2 precedes S4. In the second branch S3 precedes a nested fork: S5 runs in parallel with the sequential pair S6 then S8. The outer join waits for S4, both S5 and S8, and S7 before permitting S9.

The precedence graph (arrows are immediate dependencies) is:

          ┌→ S2 → S4 ─────────┐
          │                  │
S1 ───────┼→ S3 ─┬→ S5 ─────┼→ S9
          │      └→ S6 → S8 ─┤
          └→ S7 ─────────────┘

Its exact edge set is {(S1,S2),(S1,S3),(S1,S7),(S2,S4),(S3,S5),(S3,S6),(S6,S8),(S4,S9),(S5,S9),(S8,S9),(S7,S9)}. This is a transitive reduction: edges such as S1→S9 are implied and need not be drawn. It uses only statement vertices; explicit fork/join vertices would be an equivalent representation.

Do not add S4→S3, S5→S6, or S8→S7: textual order among separate parallel branches does not force execution order. Conversely, S9 must not start after just one branch finishes. The structure imposes control dependencies only; no extra read/write data dependencies are supplied.

Original paper, page 8