In reply to dave_59:
In reply to arun_ajs:
What makes it work is that for each iteration of the for loop, a local automatic variable is created with a lifetime that is extended by the lifetime of the fork/join_none block that references it. The statements inside the fork/join_none block begin execution after finishing the for loop. It doesn’t mater if the function/task call passes its arguments by value or by reference; each call has an independent copy of the automatic variable that was set to a value as the for loop went through its iterations.
I have a question here.
Lets say in the above example:
for(int i = 0; i < 5; i++) begin
automatic int j;
j = i;
fork
thread(j);
join_none
end
I made the following change:
for(int i = 0; i < 5; i++) begin
fork
automatic int j;
j = i;
thread(j);
join_none
end
This work fine too, but in case if I add begin-end around fork - join_none, it doesn’t work fine. Threads are spawned with 4.
Can you please what is the difference here.
Thanks
Subramaniam