Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Why Do We Need Automatic Task?

SystemVerilog Threads & Processes

The same join_none fork calling a static task, so all threads share one copy of the arguments and print the wrong names - the case that motivates automatic.

Open in IDE
testbench.sv
//--------------------------------------------------------------
// Author  : Admin, ChipVerify
// Website : www.chipverify.com
//--------------------------------------------------------------

module tb;
  initial begin
      $display ("[%0t] Main Thread: Fork join going to start", $time);
    fork
          print (20, "Thread1_0");
          print (30, "Thread1_1");
          print (10, "Thread2");              
    join_none
      $display ("[%0t] Main Thread: Fork join has finished", $time);
  end
 
  // Note that this is not an automatic task, its static
  task print (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] Thread1_0
[30] Thread1_1
ncsim: *W,RNQUIE: Simulation is complete.
ncsim> exit
*/
design.sv
// Code your design here
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.