In reply to ssubramaniam1990@gmail.com:
In reply to dave_59:
In reply to ssubramaniam1990@gmail.com:
The change you show should not work, and introduces a race condition. You are now spawning two independent threads inside the fork/join_none. The two statementsj = I; thread(j);
execute in parallel, so there is no guarantee that thread(j) gets the updated value of j. Also, the value of i at the point when j = i gets executed should be 5, for all iterations.
Adding code tags:
Hi Dave,You are right. I should have shown my code previously.
Here is my code:program automatic fork_join; initial begin for(int i = 0; i < 16; I++) begin fork // begin int index =I ; send(index); // end join_none end wait fork; end task send(int j); temp(); $display("driving port %0d %t" , j, $realtime); endtask // send endprogram
I am trying 3 different cases:
- Executing the above program, I can see the prints “Driving port 0-16”.
- In the fork block doing something like this:
fork // begin int index ; index = I ; send(index); // end join_none
With this change Driving port 16 printed 16 times.
- Adding begin-end around fork - join_none:
fork begin int index ; index = I ; send(index); end join_none
Again I see driving port16 being printed 16 times.
Can you please explain what is the difference between the 3 cases.
Thanks
Subramaniam