When the spawning of the fork join/join_any takes place

Hi ,

could you please clarify why the value of i is getting displayed as 0,1,2,3,4,5,6,7,8,9----15. I thought spawning is happening first. after spawning process execution happens.so value of I is 15 always. could you please clarify what is the meaning of process is spawned. how the spawning happens in fork join_any and for fork join


module top();
initial
begin
for (int i=0;i<16;i++)begin
fork
$display("value of i %0d",i);
join/join_any
end
#10;
end
endmodule

In reply to srbeeram:
Seems to work OK. Your code had an error

 
// Code your design here
module top();
  initial
    begin
       for (int i=0;i<16;i++)begin
         fork
            $display("value of i %0d",i);
         join_any
       end
       #10;
    end
endmodule

value of i 0
value of i 1
value of i 2
value of i 3
value of i 4
value of i 5
value of i 6
value of i 7
value of i 8
value of i 9
value of i 10
value of i 11
value of i 12
value of i 13
value of i 14
value of i 15

Ben Ben@systemverilog.us

In reply to srbeeram:

A fork join/join_any with one statement behaves much like a begin/end block with one statement. The statement executes upon entering the fork, and the join or join_any blocks until the statement completes.

The behavior you were expecting happens with a fork/join_none, which does not block. Then the for-loop finishes iterating before any statement inside the fork start executing.

In reply to dave_59:

Thanks Dave for clarification.could you clarify the following. is first iteration of for loop happens. then the first statements in fork join spawns then starts execution. then next iteration of for loop happens. then the next statements in fork join spawns , then it starts execution .it keeps on happening until all the iterations of for loop completed. could you clarify whether the explanation is correct.

In reply to srbeeram:

That explanation is correct, but I would add that whenever discussing the spawning of a process you need to also mention that the join blocks waiting for the process to complete.

In reply to dave_59:

ok Thanks for clarifications.