Could not understand output of fork join_none block

module abc;

  initial begin 
    for (int j=0; j<3; j++) 
      begin 
        fork 
          automatic int result; 
          begin result= j*j; 
            $display("Thread=%0d result=%0d", j, result); 
          end 
        join_none 
        wait fork; 
          end 
          end
  endmodule

In above code, output is:

Compiler version P-2019.06-1; Runtime version P-2019.06-1;  Oct  3 16:06 2020
Thread=0 result=0
Thread=1 result=1
Thread=2 result=4

Shouldn’t it be all as 3-9 since j is variable of for loop and not automatic variable?

In reply to juhi_p:

Due to wait fork each Iteration of for loop completes before the next Iteration Starts .

SO for 1st Iteration for j == 0 , wait_fork would block the for loop till the
immediate child thread completes . Hence we get the display with j == 0 i.e Thread=0

The 2nd Iteration of for loop ( i.e j == 1 ) starts after the 1st display statement executes.

**So essentially combination of join_none and wait fork gives a fork join behavior
**

In reply to juhi_p:

You have a wait fork statement, now it behaves similar to fork-join which means only after the finishing one thread it will go to the other thread. Remove the wait fork statement, you will see all 3-9 as output