Why is the @data not triggered on a value change?

In reply to ben@SystemVerilog.us:
Typically, one uses clocking events. The following works, regardless of the order of the blocks in the fork-join


module tb;
    bit clk; 
    initial forever #10 clk=!clk;  
    task automatic my_first_task (input logic [31:0] addr, ref  logic  [31:0] data);
        @(posedge clk);
        data = 8'h2; // non-blocking assignment may not be an automatic variable
        
        for (int i=0; i <1; i++) begin
            $display ("@ %t Entering the loop ", $realtime);
        end
        
        for (int i=0; i <1; i++) begin
            $display ("Entering the second loop");
        end
    endtask
    
    logic [31:0] addr, data;
    
    initial  begin
        data = 'h10;
        addr = 'h01;
        fork 
                     
            begin
                // @(posedge clk);                 
                @ (data);
                $display ("@ %t Read from bus %h \n", $realtime, data);
            end 

            my_first_task (addr,data);
        join
    end
endmodule
 
# @                   10 Entering the loop 
# Entering the second loop
# @                   10 Read from bus 00000002 
# 
 

****NOTE
The following has a race condition

 
module tb;
    bit clk; 
    initial forever #10 clk=!clk;  
    task automatic my_first_task (input logic [31:0] addr, ref  logic  [31:0] data);
        @(posedge clk);
        data = 8'h2; // non-blocking assignment may not be an automatic variable
        
        for (int i=0; i <1; i++) begin
            $display ("@ %t Entering the loop ", $realtime);
        end
        
        for (int i=0; i <1; i++) begin
            $display ("Entering the second loop");
        end
    endtask
    
    logic [31:0] addr, data;
    
    initial  begin
        data = 'h10;
        addr = 'h01;
        fork 
                     
            begin
                @(posedge clk);      
                $display ("@ %t Before the @data %h \n", $realtime, data);           
                @ (data); // <<< Gets bloked here, waiting for a new change 
                $display ("@ %t Read from bus %h \n", $realtime, data);
            end 

            my_first_task (addr,data);
        join
        $display ("@ %t After the joins %h \n", $realtime, data);
    end
endmodule

@                   10 Entering the loop 
# Entering the second loop
# @                   10 Before the @data 00000002 



WIth the #1 as in 
@(posedge clk); #1; 
        data = 8'h2; 
It WORKS OK 

 @                   10 Before the @data 00000010 
# 
# @                   11 Entering the loop 
# Entering the second loop
# @                   11 Read from bus 00000002 
# 
# @                   11 After the joins 00000002 
#  

BTW, this forum does not discuss tools. One should ever identify the tool you are using. You can just say “my tool deos this”, but in the this, delete anything that can identify the tool. Your question is Not a tool issue, but a SystemVerilog issue.
Ben Cohen
http://www.systemverilog.us/ ben@systemverilog.us
For training, consulting, services: contact Home - My cvcblr


  1. SVA Alternative for Complex Assertions
    Verification Horizons - March 2018 Issue | Verification Academy
  2. SVA: Package for dynamic and range delays and repeats | Verification Academy
  3. SVA in a UVM Class-based Environment
    SVA in a UVM Class-based Environment | Verification Horizons | Verification Academy