SystemVerilog Reference
fork with join, join_any and join_none
A fork starts its statements as parallel processes. The closing keyword says how long the parent waits.
Syntax
fork
task_a();
task_b();
join // wait for all
// join_any wait for the first to finish
// join_none do not waitRules
joinwaits for every child.join_anywaits for the first child. The others keep running.join_nonedoes not wait. The children start when the parent next blocks.wait forkwaits for all children of the current process.disable forkstops all children of the current process.
Example
module tb;
task automatic work(input string name, input int delay);
#delay $display("t=%0t %s done", $time, name);
endtask
initial begin
fork
work("a", 10);
work("b", 30);
join_any
$display("t=%0t after join_any", $time);
wait fork;
$display("t=%0t after wait fork", $time);
end
endmodulet=10 a done
t=10 after join_any
t=30 b done
t=30 after wait forkCommon Mistake
Every child sees the last loop value
for (int i = 0; i < 3; i++)
fork
$display(i); // the standard prints 3, 3, 3
join_noneThe children start after the loop has finished, and they share one i. By then i is 3.
Fix: Copy it inside the fork: fork automatic int k = i; $display(k); join_none.
Learn It Properly
These lessons teach it step by step, with practice problems.
Standard
IEEE 1800-2023, 9.3.2.