Please see the below thread to understand the “scope” of ‘disable fork’
What’s happening here is that the disable fork is killing all the threads swapned by the parent fork, but doesn’t kill the parent fork itself.
You are working around that by using a “label”. Note that using a “label” isn’t foolproof either, you may end up running the fork with multiple instances of the class, and all the “labels” will get killed, which may not be what you want. So keep that in mind.
I would prefer the following code instead :
module top;
event a, b, c;
initial
begin
fork begin//isolator
bit disable_fork_condition;
fork
begin
#10 $display("%t 1st process", $time);
-> a;
end
begin
#20 $display("%t 2nd process", $time);
->b;
end
begin
#30 $display("%t 3rd process", $time);
->c;
end
begin
int count='0;
while(1)
begin
@(a or b or c)
count++;
$display("%d", count);
if(count == 32'd2)
begin
$display("disable fork");
disable_fork_condition = 1;
break;
end
end
end
join_any
wait(disable_fork_condition == 1);
disable fork;
end join //isolator
$display("Completed");
end
endmodule