VLSI DV Interview Puzzles · All levels
wait fork Synchronization Point
Order these prints by time and explain what `wait fork` waits for.
Puzzle
Difficulty: Easy · Puzzle 3 of 6 · Topic: Fork Join Puzzles
Order these prints by time and explain what `wait fork` waits for.
Code
systemverilog
module p3;
initial begin
fork
#3 $display("%0t A", $time);
#7 $display("%0t B", $time);
join_none
$display("%0t parent_after_join_none", $time);
wait fork;
$display("%0t parent_after_wait_fork", $time);
end
endmoduleHint
`join_none` returns immediately, but `wait fork` blocks until all currently active children from this process finish.
Step-by-step solution
diagram
1) Parent prints `parent_after_join_none` at t=0 immediately after spawning children.
2) Child A prints at t=3.
3) Child B prints at t=7.
4) `wait fork` unblocks only after both children complete, so final parent print is at t=7.Answer
Answer: parent_after_join_none@0, A@3, B@7, parent_after_wait_fork@7
Why candidates get it wrong
A frequent miss is assuming `wait fork` only waits for the most recently spawned child.
Interviewer follow-up
What if another nested fork starts a forever loop before `wait fork`?