Fork in a for loop

**Consider the code;
**

module tb;	  
    initial begin    
        for (int i = 0; i<3; i++) begin
            fork
                begin
                    automatic int j = i;
                    print(j);
                end
            join_none
        end        
        #50 $finish;
    end    

    task automatic print (input int i);
        #10
        $display($time, "ns || %d", i);
    endtask    
endmodule

It prints, 3 thrice all at 10ns.
I want it to print, 0,1,2 all at 10ns. What should I do?

Declaring the automatic variable outside the fork-join_none prints, 2,1,0 all at time 10ns.

        for (int i = 0; i<3; i++) begin
            automatic int j = i;     
            fork
                begin
                    print(j);
                end
            join_none
        end

I am really confused about what is actually happening here.

In reply to Husni Mahdi:


module tb;	  
    initial begin    
      **for (int i = 2; i>=0; i--)** begin
          **automatic int j = i;**
            fork
                begin
                   //automatic int j = i;
                    print(j);
                end
            join_none
        end        
        #50 $finish;
    end    
 
    task automatic print (input int i);
        #10
        $display($time, "ns || %d", i);
    endtask    
endmodule

output :-

10ns || 0

10ns || 1

10ns || 2

In reply to Husni Mahdi:

Reason for why you code is displaying only 3 all thrice because, as you have fork join_none inside for loop , until the loop completes fork join_none’s spawned thread will not start execute it will just be scheduled ,and by the time it start execute value of ‘i’ will be update to incremented value which is 3.