# The difference between a looped \`fork...join\_none\` and a serial \`fork...join\_none\`

**URL:** <https://verificationacademy.com/forums/t/the-difference-between-a-looped-fork-join-none-and-a-serial-fork-join-none/51702>\
**Category:** SystemVerilog\
**Created:** [July 6, 2026, 10:00am UTC](https://verificationacademy.com/forums/t/the-difference-between-a-looped-fork-join-none-and-a-serial-fork-join-none/51702 "2026-07-06T10:00:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![doggkin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/7993a0/32.png) [@doggkin](https://verificationacademy.com/forums/u/doggkin)\
**Post date:** [July 6, 2026, 10:00am UTC](https://verificationacademy.com/forums/t/the-difference-between-a-looped-fork-join-none-and-a-serial-fork-join-none/51702/1 "2026-07-06T10:00:07Z")

</div>

Hi all,

When I use a loop in a module and declare a variable `a` within a `fork...join_none`, that variable should have a static lifetime, and its scope should be limited to the `fork...join_none`.

```vhdl
initial begin
  repeat(2) begin
    fork
      int a;      
      begin
        a++;
        $display("a is %0d", a);
      end
    join_none
  end
  wait fork;
end

```

As I understand it, a new `fork...join_none` should be created for each iteration of the loop. Therefore, the two loops in the snippet above create two `fork...join_none` instances, and variable `a` should be initialized in both of them. Consequently, `a` should ultimately print 1 in both cases, but in reality, it prints 1 and 2.

Later, I tried a serial `fork...join_none`, and this time the results were as expected—both were 1. Why is that?

```vhdl
initial begin 
  fork
    int a;
    begin
      a++;
      $display("a is %0d", a);
    end
  join_none

  fork
    int a;
    begin
      a++;
      $display("a is %0d", a);
    end
  join_none
  wait fork;
end

```

It seems that the two `fork...join_none` instances of repeat are sharing the same variable.

BR

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [July 6, 2026, 3:03pm UTC](https://verificationacademy.com/forums/t/the-difference-between-a-looped-fork-join-none-and-a-serial-fork-join-none/51702/2 "2026-07-06T15:03:51Z")

</div>

SystemVerilog allocates and initializes static variables once at the beginning of the simulation before any `initial` or `always` blocks begin execution. To create a new instance of `a` for each iteration of the loop, declare it as `automatic int a;`.

---

<div class="post-metadata">

**Author:** ![doggkin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/7993a0/32.png) [@doggkin](https://verificationacademy.com/forums/u/doggkin)\
**Post date:** [July 6, 2026, 4:53pm UTC](https://verificationacademy.com/forums/t/the-difference-between-a-looped-fork-join-none-and-a-serial-fork-join-none/51702/3 "2026-07-06T16:53:05Z")

</div>

Thanks dave, I understand what you mean, but I think the variable `a` is declared within `fork...join_none`, so its scope is limited to `fork...join_none`. Since the two loops create two `fork...join_none` blocks, each `fork...join_none` should have its own `a` with a static lifetime, and the two `a`s should be independent of each other. However, the results seem to indicate that the two `a`s are the same.

---

<div class="post-metadata">

**Author:** ![doggkin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/7993a0/32.png) [@doggkin](https://verificationacademy.com/forums/u/doggkin)\
**Post date:** [July 7, 2026, 2:00am UTC](https://verificationacademy.com/forums/t/the-difference-between-a-looped-fork-join-none-and-a-serial-fork-join-none/51702/4 "2026-07-07T02:00:07Z")

</div>

I thought about it carefully, and I wonder if I can understand it this way.

There is only one `begin...end` block here, and within that block there is only one `fork...join_none` block; there is also only one variable declared within the `fork...join_none` block. The loop simply repeats the execution of the same `begin...end` block, similar to a method call. Therefore, when variable `a` is declared as static, even if the loop runs multiple times, the static variable `a` will only be initialized once.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [July 7, 2026, 5:26am UTC](https://verificationacademy.com/forums/t/the-difference-between-a-looped-fork-join-none-and-a-serial-fork-join-none/51702/5 "2026-07-07T05:26:52Z")

</div>

Yes, I think your last post suggests you are beginning to understand it.

You might want to read my DVCon paper:

> **[the-life-of-a-systemverilog-variable.pdf](https://dvcon-proceedings.org/wp-content/uploads/the-life-of-a-systemverilog-variable.pdf)**
>
> 235.61 KB

---

<div class="post-metadata">

**Author:** ![doggkin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/7993a0/32.png) [@doggkin](https://verificationacademy.com/forums/u/doggkin)\
**Post date:** [July 7, 2026, 5:55am UTC](https://verificationacademy.com/forums/t/the-difference-between-a-looped-fork-join-none-and-a-serial-fork-join-none/51702/6 "2026-07-07T05:55:42Z")

</div>

Much appreciated.
