Below code as fork join_none block, Has fork join_none spawn the forked threads and starts executing the main threads first, then spawned threads will be executed, I was expecting Thread A in the fork as to be disabled from the below code.
But Thread A is also working Please clarify this.
module test;
initial begin
fork:fork_name
begin:C
$display("time = %0d, Thread C has started ",$time );
# (20);
$display("time = %0d, Thread C has finished ",$time );
end
begin:A
$display("time = %0d, Thread A has started ",$time );
#(10);
$display("time = %0d, Thread A has finished ",$time );
end
begin:B
$display("time = %0d, Thread B has started ",$time );
#(5);
$display("time = %0d, Thread B has finished ",$time );
end
join_none
disable fork_name.A;
$display("time = %0d Outside the main fork ",$time );
end
endmodule
Result:-
time = 0 Outside the main fork
time = 0, Thread C has started
time = 0, Thread A has started
time = 0, Thread B has started
time = 5, Thread B has finished
time = 10, Thread A has finished
time = 20, Thread C has finished
Expected Result :-
time = 0 Outside the main fork
time = 0, Thread C has started
time = 0, Thread B has started
time = 5, Thread B has finished
The disable statement can only be used on active processes. Since you call disable prior to any of the forked blocks starting, there is no existing process to disable.
Putting a blocking statement before the disable statement allows the forked processes to start and you can then disable the one desired.
Hi cgales, As you suggested I have inserted a blocking statement before disable. But Still, the result is the same as before.
module test;
int a;
initial begin
fork:fork_name
begin:C
$display("time = %0d, Thread C has started ",$time );
# (20);
$display("time = %0d, Thread C has finished ",$time );
end
begin:A
$display("time = %0d, Thread A has started ",$time );
#(10);
$display("time = %0d, Thread A has finished ",$time );
end
begin:B
$display("time = %0d, Thread B has started ",$time );
#(5);
$display("time = %0d, Thread B has finished ",$time );
end
join_none
a = 10;
disable fork_name.A;
$display("time = %0d Outside the main fork ",$time );
end
endmodule
module test;
initial begin
fork:fork_name
begin:C
$display("time = %0d, Thread C has started ",$time );
# (20);
$display("time = %0d, Thread C has finished ",$time );
end
begin:A
$display("time = %0d, Thread A has started ",$time );
#(10);
$display("time = %0d, Thread A has finished ",$time );
end
begin:B
$display("time = %0d, Thread B has started ",$time );
#(5);
$display("time = %0d, Thread B has finished ",$time );
end
join_none: fork_name
#1;
disable fork_name.A;
$display("time = %0d Outside the main fork ",$time );
end
endmodule
So #1 is an delay which may disable the thread which is only after #1 time in that block. But what if i want to disable the whole block including first display which is getting printed @0ns.
begin:A
$display("time = %0d, Thread A has started ",$time );
#(10);
$display("time = %0d, Thread A has finished ",$time );
end
System Verilog says: “spawned processes do not start executing until the parent thread executes a blocking statement”. So even
a=10;
before disable fork; statement is also blocking statement only. Why that is not endorsed. Please clarify.
You can’t disable a block before it starts. If you don’t want the block to start, use a conditional before it is forked. Why would you fork a block if you don’t want it to at least start?
The statement ‘a=10’ is a blocking assignment that only relates to how the variable is assigned. It has nothing to do with blocking from a scheduler standpoint.