VLSI DV Interview Puzzles · All levels
join vs join_any vs join_none
Give the timeline of all prints and identify which children survive each block.
Puzzle
Difficulty: Easy · Puzzle 1 of 6 · Topic: Fork Join Puzzles
Give the timeline of all prints and identify which children survive each block.
Code
systemverilog
module p1;
initial begin
fork
begin #5 $display("%0t A", $time); end
begin #10 $display("%0t B", $time); end
join
$display("%0t join_done", $time);
fork
begin #5 $display("%0t C", $time); end
begin #10 $display("%0t D", $time); end
join_any
$display("%0t join_any_done", $time);
disable fork;
fork
begin #5 $display("%0t E", $time); end
begin #10 $display("%0t F", $time); end
join_none
$display("%0t join_none_done", $time);
#1 disable fork;
end
endmoduleHint
Analyze each fork block independently, but remember simulation time accumulates because they execute sequentially in one initial block.
Step-by-step solution
diagram
1) First block (`join`) waits for both children: A at t=5, B at t=10, then `join_done` at t=10.
2) Second block starts at t=10: C at t=15, parent resumes at `join_any` and prints `join_any_done` at t=15, then `disable fork` kills D.
3) Third block starts at t=15: `join_none_done` prints immediately at t=15, then parent waits #1 and kills both detached children at t=16 before E/F can print.Answer
Answer: A@5, B@10, join_done@10, C@15, join_any_done@15, join_none_done@15; D/E/F never print
Why candidates get it wrong
People remember only 'parallel' and forget parent resumption semantics and explicit cleanup needs.
Interviewer follow-up
What changes if the third block removes `#1` and calls `disable fork;` immediately?