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 wait

Rules

  • join waits for every child.
  • join_any waits for the first child. The others keep running.
  • join_none does not wait. The children start when the parent next blocks.
  • wait fork waits for all children of the current process.
  • disable fork stops 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
endmodule
Output on Icarus Verilog 12
t=10 a done
t=10 after join_any
t=30 b done
t=30 after wait fork

Run It in the Playground

Common 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_none

The 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.