SystemVerilog Fork Join

fork join

Fork-Join will start all the processes inside it parallel and wait for the completion of all the processes.

SystemVerilog Fork Join
SystemVerilog Fork Join

fork join example

In below example,

fork block will be blocked until the completion of process-1 and Process-2.

Both process-1 and Process-2 will start at the same time, Process-1 will finish at 5ns and Process-2 will finish at 20ns. fork-join will be unblocked at 20ns.

module fork_join;

  initial begin
    $display("-----------------------------------------------------------------");
    fork
      //-------------------
      //Process-1
      //-------------------
      begin
        $display($time,"\tProcess-1 Started");
        #5;
        $display($time,"\tProcess-1 Finished");
      end

      //-------------------
      //Process-2
      //-------------------
      begin
        $display($time,"\tProcess-2 Started");
        #20;
        $display($time,"\tProcess-2 Finished");
      end
    join
    $display($time,"\tOutside Fork-Join");
    $display("-----------------------------------------------------------------");
    $finish;
  end
endmodule

Simulator Output

-----------------------------------------------------------------
0 Process-1 Started
0 Process-2 Startedt
5 Process-1 Finished
20 Process-2 Finished
20 Outside Fork-Join
-----------------------------------------------------------------

Click to execute on

❮ Previous Next ❯