Hi.
I would like to monitor the change of a class variable from the outside and stop the loop of a task defined in the class when it reaches a certain value.
In the following code, if I use forkA, the simulation ends after mc.value changes to 10, but if I use forkB instead of forkA, the loop does not exit.
I would like to know the reason.
(I used VCS as simulator)
class myclass;
int value;
function new;
value=0;
endfunction
task value_inc;
while(1)begin
value++;
#10;
end
endtask
function int get_value;
return value;
endfunction
endclass
module sim_top;
myclass mc = new();
initial begin
fork //fork A
mc.value_inc();
wait(mc.value==10) #1;
join_any
disable fork;
// fork //fork B
// mc.value_inc();
// wait(mc.get_value()==10) #1; // The wait statement does not terminate.
// join_any
// disable fork;
$display("mc.value=%-d",mc.value); //10
$display("mc.get_value()=%-d",mc.get_value()); //10
$finish;
end
initial begin
#10000000;
$display("sim aborted");
$finish;
end
endmodule
As Dave said, the following works and it makes sense since
this is an event-based simulator. Without a variable argument, the function is never called again.
The function is a function; it just resides there until called.
function int get_value(int v);
return v;
endfunction
endclass
module sim_top;
myclass mc = new();
initial begin
fork //fork A
mc.value_inc();
wait(mc.get_value(mc.value)==10) #1;
join_any
disable fork;
A class method does not need a input argument to trigger the event. Writing to a class member does. 3 out of 4 tools on EDAPlayground simulate this correctly. This is a tool bug.