module my_program;
int unsigned num = 3;
int unsigned max_delay = 3;
initial begin
for (int i = 0; i < num; i++) begin
$display("%t : For loop entered . Iteration %0d", $time, i);
fork
automatic int local_i = i;
$display("%t : Assigned local variable local_i = %0d", $time, local_i);
begin
automatic int j = local_i;
$display("%t child begin-end process %d is started and will do #%0d delay",
$time, local_i, j);
#j;
$display("%t child begin-end process %0d finished",
$time, local_i);
end // begin
join_none
end // end for loop
$display("%t : For loop completed, now starting wait of %0d time units", $time, (num + 1));
#(num + 1);
disable fork;
end // initial
endmodule
It is not clear to me what LRM specifies "Automatic variables declared in the scope of the fork?join block shall be initialized to the initialization value whenever execution enters their scope, and before any processes are spawned."
Q2: When was the execution scope of the fork join block actually entered and when is the begin..end scope entered?
Q3: Are
automatic int local_i = i;
and
begin ... end
considered parallel threads inside the fork join_none? Then how do we guarantee that assignment happens before begin .. end