SystemVerilog fork join, join_any and join_none
Compare fork...join, join_any and join_none, control child processes, and avoid loop-variable and disable-fork mistakes.
Three join behaviors
fork...join starts every child process and waits until all finish. join_any resumes the parent after the first child finishes. join_none starts the children without waiting; the parent continues immediately.
fork
drive_request();
monitor_response();
join
For a timeout pattern, wait for either the operation or timer, then stop the remaining child:
fork
begin wait (done); completed = 1; end
begin #1us; timed_out = 1; end
join_any
disable fork;
disable fork terminates all active child processes of the calling process, including descendants. Put the fork inside a dedicated wrapper process when unrelated children might otherwise be stopped.
Waiting after join_none
The spawned children do not begin executing until the parent thread suspends or terminates. Use wait fork when the parent later needs to wait for all its outstanding children.
Loop-variable trap
Create an automatic copy for each spawned process:
for (int i = 0; i < 4; i++) begin
automatic int index = i;
fork
send(index);
join_none
end
wait fork;
Without the per-iteration copy, delayed children can observe the loop variable after it has advanced. Verify process lifetime explicitly: identify what starts each thread, what ends it, how reset or timeout cancels it, and whether resources are released on every exit path.