Automatic variables in fork

In reply to dave_59:

Hi Dave,
thanks a lot for the explanation. It is clear now. I have a related question:
If I move the automatic variable declaration and initialization outside fork statement, as given below:

case 5:

program automatic test4;
  initial begin
    for (int j = 0; j < 3; j++) begin
      automatic int k = j; 
      fork //begin
       
        // k = j;
 
        $write (k);
      //end
      join_none
    end
    #0 $display ("\n test");
  end
 
endprogram

Then the result it displays is 2 2 2 (since the final value of k after the for loop completes will be 2, which will be used by $write (k)). However, in the Chris Spear book (system verilog for verification, second edition) on page 226/227, it says case 1 and case 5 should give same result. This is confusing. Can you please comment on this.

regards,
-sunil