SourceSV Verification Directory

Fork Join Any

Fork join any construct is similar to Fork Join but the simulation process does not wait till all the threads are completed. It proceeds to the next execution statement as soon as any one of the threads completes the process.

Fork join any is depicted in the figure below.

Syntax: Fork Join Any

fork
   // process 1
   // process 2
   // process 3
join_any

Example Code: Fork Join Any

module tb_fork_join_any;

  initial begin
    fork
      #2  $display("t = %0t, fork 1 => process 1", $time);
      #10 $display("t = %0t, fork 1 => process 2", $time);
      #5  $display("t = %0t, fork 1 => process 3", $time);
    join_any
    $display("--------------- Exited Fork 1 ---------------");
    end


  initial begin
    fork
      #3 $display("t = %0t, fork 2 => process 1", $time);
      #6 $display("t = %0t, fork 2 => process 2", $time);
      #1 $display("t = %0t, fork 2 => process 3", $time);
    join_any
    $display("--------------- Exited Fork 2 ---------------");
    end

endmodule

Execute the code in EDA Playground