class disablefork;
task fork1stmt;
fork
begin : fork_1
#2ns;
$display("fork1stmt at %0tns", $time);
//disable fork_2; //- DISABLED fork_2
end
begin : fork_2
fork2stmt();
$display("fork2stmt at %0tns", $time);
#5ns;
$display("5ns delay fork_2 at %0tns", $time);
end
disable fork_2; //DOES NOT DIABLE fork_2 named block if fork2stmt() has fork-join inside
$display("fork1stmt: Outside begin-end blocks at %0tns", $time);
join_none
endtask
task fork2stmt;
fork
begin
#10ns;
$display("fork-join_any: fork2stmt-1 at %0tns", $time);
end
$display("fork-join_any: fork2stmt-2 at %0tns", $time);
join_any
fork
begin
$display("fork-join_none: fork2stmt-1 at %0tns", $time);
#10ns;
$display("fork-join_none: fork2stmt at %0tns", $time);
end
join_none
endtask
endclass
module tb_top();
initial begin
disablefork disableforkex_i;
disableforkex_i = new();
disableforkex_i.fork1stmt();
end
endmodule
Result:
**fork-join_any: fork2stmt-2 at 0ns**
fork2stmt at 0ns
fork-join_none: fork2stmt-1 at 0ns
fork1stmt: Outside begin-end blocks at 0ns
fork1stmt at 2ns
fork-join_any: fork2stmt-1 at 10ns
fork-join_none: fork2stmt at 10ns
Question:
In this example, the fork2 named block comes out of fork2stmt() task call at 0ns. Hence the time when “disable fork_2” is executed, the simulator is aware of fork_2 named begin block. It does terminate the block from execution. This is the reason the result does not print “5ns delay fork_2” statement.
However, it goes on to complete the pending threads forked out of fork2stmt() task.
“fork-join_any: fork2stmt-2 at 0ns” is the first print in the result. This implies the begin/end inside the fork-join_any in fork2stmt()task should be visible when disable fork_2 is executed. (Assuming fork-join_none in fork2stmt() has not yet started, say that explains why it’s not killed)
Question: How come only the parent processes are visible and not the child threads spawned out of fork2stmt are visible in this case?
Another observation is that when the fork-join_none inside the fork2stmt() is changed to fork-join(blocking), “disable fork_2” disables the pending prints from fork-join in fork2stmt(). fork-join_any still continues to complete. In this result as well, fork-join_any is the first print statement.
Result :
fork-join_any: fork2stmt-2 at 0ns
fork-join_none: fork2stmt-1 at 0ns
fork1stmt: Outside begin-end blocks at 0ns
fork1stmt at 2ns
fork-join_any: fork2stmt-1 at 10ns