Member 'Downloads' section will be deprecated from Jan 1, 2020.

There is a third type of fork join in SystemVerilog which is fork and join_none.

A fork and join_none will allow the main thread to resume execution of further statements that lie after the fork regardless of whether the forked threads finish. If five threads are launched, the main thread will resume execution immediately while all the five threads remain running in the background.

Syntax

 
  fork
    // Thread 1
    // Thread 2
    // ...
    // Thread N
  join_none
 

fork join_none Example

 
module tb;
  initial begin
      $display ("[%0t] Main Thread: Fork join going to start", $time);
    fork
          display (20, "Thread1_0");
          display (30, "Thread1_1");
          display (10, "Thread2");              
    join_none
      $display ("[%0t] Main Thread: Fork join has finished", $time);
  end
 
  task display (int _time, string t_name);
    #(_time) $display ("[%0t] %s", $time, t_name);
  endtask
endmodule
 
Simulation Log
ncsim> run
[0] Main Thread: Fork join going to start
[0] Main Thread: Fork join has finished
[10] Thread2
[20] Thread2
[30] Thread2
ncsim: *W,RNQUIE: Simulation is complete.

Click to try this example in a simulator!   

Nested fork join_none

 
module tb;
  initial begin
      $display ("[%0t] Main Thread: Fork join going to start", $time);
    fork
          begin
      fork
              display (20, "Thread1_0");
              display (30, "Thread1_1");
            join_none
            $display("[%0t] Nested fork has finished", $time);
          end
          display (10, "Thread2");              
        join_none
      $display ("[%0t] Main Thread: Fork join has finished", $time);
  end
 
  task display (int _time, string t_name);
    #(_time) $display ("[%0t] %s", $time, t_name);
  endtask
endmodule
 
Simulation Log
ncsim> run
[0] Main Thread: Fork join going to start
[0] Main Thread: Fork join has finished
[0] Nested fork has finished
[10] Thread2
[20] Thread2
[30] Thread2
ncsim: *W,RNQUIE: Simulation is complete.

Click to try this example in a simulator!   

Using automatic task

It can be seen in the previous example that the same display task with different string tags produced the same display message. This is because multiple threads call the same task and share the same variable in tool simulation memory. In order for different threads to initiate different copies of the same task, automatic keyword has to be used.

 
  // Code above this remains the same
 
  task automatic display (int _time, string t_name);
    #(_time) $display ("[%0t] %s", $time, t_name);
  endtask
 
Simulation Log
ncsim> run
[0] Main Thread: Fork join going to start
[0] Main Thread: Fork join has finished
[0] Nested fork has finished
[10] Thread2
[20] Thread1_0
[30] Thread1_1
ncsim: *W,RNQUIE: Simulation is complete.

Click to try this example in a simulator!   

You consent to our cookies if you continue to use our website. To know more about cookies, see our privacy policy. I accept cookies from this site.

Agree