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

Event: How to Trigger and Wait for an Event

SystemVerilog Interprocess Communication

Runnable example from the SystemVerilog Event tutorial (How to Trigger and Wait for an Event)

Open in IDE
testbench.sv
module tb;
  
  // Create an event variable that processes can use to trigger and wait
  event event_a;
  
  // Thread1: Triggers the event using the non-blocking "->>" operator at 20ns
  initial begin
    #20 ->>event_a;
    $display ("[%0t] Thread1: triggered event_a", $time);
  end
  
  // Thread2: Also starts waiting for the event using "@" at 20ns - the exact
  // same race setup that made Thread2 miss the trigger with "->" earlier
  initial begin
    $display ("[%0t] Thread2: waiting for trigger ", $time);
    #20 @(event_a);
    $display ("[%0t] Thread2: received event_a trigger ", $time);
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.