System Verilog fork join_none with for loop & delay

for(i=0; i<5; i++) begin
  fork
    $display("i=%0d",i);
  join_none
end

In the above case output will be : 5 5 5 5 5 is it because of fork join_none threads wont be spawned until the parent thread executes blocking task i.e (for loop executing )?

for(i=0; i<5; i++) begin
 #0;
fork
$display("i=%0d",i);
join_none
end

In 2nd case the output is i.e, value of i will be 1 2 3 4 5 ,Need clarification wrt to below queries

  1. why output is 1 2 3 4 5 rather than 0 1 2 3 4 ?
  2. when any delay are introduced in the for loop how execution it is different from case 1 ?

Thsnks
venkat

In reply to venkatarami reddy:

You are are correct in the first case none of the forked threads start executing until the parent thread blocks or terminates.

If you unroll the for-loop in the second case, you get your answers

i=0;
 #0;
fork
$display("i=%0d",i);
join_none
i++; 
 #0; // i is 1
fork
$display("i=%0d",i);
join_none
i++; 
 #0; // i is 2
fork
$display("i=%0d",i);
join_none
i++; 
 #0; // i is 3
fork
$display("i=%0d",i);
join_none
i++; 
 #0; // i is 4
fork
$display("i=%0d",i);
join_none
i++l 
// i is 5

In reply to dave_59:

In reply to venkatarami reddy:
You are are correct in the first case none of the forked threads start executing until the parent thread blocks or terminates.
If you unroll the for-loop in the second case, you get your answers

i=0;
#0;
fork
$display("i=%0d",i);
join_none
i++; 
#0; // i is 1
fork
$display("i=%0d",i);
join_none
i++; 
#0; // i is 2
fork
$display("i=%0d",i);
join_none
i++; 
#0; // i is 3
fork
$display("i=%0d",i);
join_none
i++; 
#0; // i is 4
fork
$display("i=%0d",i);
join_none
i++l 
// i is 5
  1. since #0 blocking statements executes in NBA region and 2 ) for loop it gets repeated for 4 times so we are getting output as 1 2 3 4 3)and increment of i happens post fork join_none execution in this case
    ?

In reply to venkatarami reddy:

#0 blocking statement suspends the parent thread to the in-active region.

For loop iterates 5 times. (Saying it executes once then repeats 4 times is technically correct, but an odd way of expressing it)

Increment of i happens after scheduling fork/join_none process, then #0 blocking statement causes forked $display to execute. Then parent thread resumes in the next active region.

Hi @dave_59 , can you please add more explanation for 2nd case ? I am able to co-relate with SV event scheduler ?

I got the clarity for 2nd case -
the fork_join_none statements are
scheduled to be executed at the end of the active region . statement after fork join_none (i.e i++ values is changed first) and then before moving to inactive
regions (i.e. next #0 statement ), the simulator runs the “i : %0d” statements;