Tutorials

Learn More

Passing an event in the class constructor

When a class object is created, an event is passed to the constructor as shown in the below example.

class transaction;
  event tr_e;
  
  function new(event e1);
    tr_e = e1;
  endfunction
  
  task process_A();
    #10;
    ->tr_e;
    $display("@%0t: process_A: tr_e is triggered", $time);
  endtask

  task process_B();
    $display("@%0t: process_B: waiting for the event tr_e", $time);
    wait(tr_e.triggered);
    $display("@%0t: process_B: event tr_e is received", $time);
  endtask
endclass

module event_example();
  transaction tr;
  event ev;
  
  initial begin
    tr = new(ev);
    fork
      tr.process_A();
      tr.process_B();
    join
  end
endmodule

Output:

@0: process_B: waiting for the event tr_e
@10: process_A: tr_e is triggered
@10: process_B: event tr_e is received

Passing an event as an argument in the task or function

An event can also be passed to a function or task as below.

module event_example();  
  function process_A(event e1);
    ->e1;
    $display("@%0t: process_A: e1 is triggered", $time);
  endfunction
  
  initial begin
    event e1;
    fork
      process_A(e1);
      begin
        $display("@%0t: process_B: waiting for the event e1", $time);
        wait(e1.triggered);
        $display("@%0t: process_B: event e1 is received", $time);
      end
    join
  end
endmodule

Output:

@0: process_A: e1 is triggered
@0: process_B: waiting for the event e1
@0: process_B: event e1 is received

System Verilog Tutorials