# Fork within loop with join ALL

**URL:** <https://verificationacademy.com/forums/t/fork-within-loop-with-join-all/27948>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [May 31, 2012, 8:16am UTC](https://verificationacademy.com/forums/t/fork-within-loop-with-join-all/27948 "2012-05-31T08:16:50Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![Michael\_D\_Scott](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@Michael\_D\_Scott](https://verificationacademy.com/forums/u/Michael_D_Scott)\
**Post date:** [April 17, 2020, 1:05pm UTC](https://verificationacademy.com/forums/t/fork-within-loop-with-join-all/27948/18 "2020-04-17T13:05:28Z")

</div>

_In reply to [zz8318](https://verificationacademy.com/forums/t/fork-within-loop-with-join-all/27948/17):_

> _In reply to [dave\_59](https://verificationacademy.com/forums/t/fork-within-loop-with-join-all/27948/17):_  
> Hi Dave,  
> If I have two for-loop, how to handle it ? Is below code correct ?

```verilog

fork 
begin : isolating_thread
for(int index=0;index<14;index++)begin : for_loop
fork
automatic int idx=index;
for(int j=0;j<14;j++)begin 
automatic int jdx=j;
begin
`ovm_do_on(sequence_inst,p_sequencer.my_sqr[idx][jdx]);
end
join_none;
end : for_loop
wait fork;
end
end : isolating_thread
join

```

That should work, not sure you need that second automatic variable assignment for j, but it shouldn’t hurt.

I just ran into this problem yesterday… great thread… I totally missed the part about the automatic variable for the fork.

---

_[View the full topic](https://verificationacademy.com/forums/t/fork-within-loop-with-join-all/27948)._
