I am trying to do a disable on a named fork in a class method. My requirement is that I should only disable fork in the class object where I am calling disable statement. But the below code seems to disable ‘new_wait’ blocks of other objects too. How do I name the fork so that only the specific object’s fork statement gets disabled.
Output with my requirement-
I am at time 3
I am at time 7
Observed output-
I am at time 3
class abc;
int timer;
function new(int t);
this.timer = t;
endfunction: new
task waiting();
fork: new_wait
begin
#(timer*1ns);
$display("I am at time %0d", timer);
end
begin
#5ns;
end
join_any
disable new_wait;
endtask
endclass
module top;
abc x = new(3);
abc y = new(7);
initial begin
fork
x.waiting();
y.waiting();
join
end
endmodule
I have added few displays in your code for better debug visibility.
`timescale 1ns/1ps
class abc;
int timer;
function new(int t);
this.timer = t;
endfunction: new
task waiting();
fork: new_wait
begin
#(timer*1ns);
$display("%t : I am at time %0d", $time, timer);
end
begin
#5ns;
end
join_any
$display("%t : Disabling new_wait for timer : %0d", $time, timer);
disable new_wait;
endtask
endclass
module top;
abc x = new(3);
abc y = new(7);
initial begin
fork
x.waiting();
y.waiting();
join
end
endmodule
The corresponding output is
3000 : I am at time 3
3000 : Disabling new_wait for timer : 3
3000 : Disabling new_wait for timer : 7
It’s clear from the output that thread new_wait for both the instances x and y is getting terminated because of calling waiting method of instance x.
Systemverilog LRM gives below comparision for disable thread and disable fork.
Verilog supports the disable construct, which terminate a process when applied to the named block being
executed by the process. The disable fork statement differs from disable in that disable fork considers
the dynamic parent-child relationship of the processes, whereas disable uses the static, syntactical information of the disabled block. Thus, disable shall end all processes executing a particular block, whether the
processes were forked by the calling thread or not, while disable fork shall end only those processes that Accellera were spawned by the calling thread.