# Confusion in fork join ... disable fork

**URL:** <https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [June 26, 2013, 6:12pm UTC](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662 "2013-06-26T18:12:25Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![sbollemp](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/b9bd4f/32.png) [@sbollemp](https://verificationacademy.com/forums/u/sbollemp)\
**Post date:** [December 7, 2016, 12:04pm UTC](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662/22 "2016-12-07T12:04:39Z")

</div>

Hi Dave,

Can you please explain the below code.

```verilog
module top_fork();
  

  task task1();
    forever begin
      #5;
      $display("in task1");
    end
  endtask
  
  task task2();
    forever begin
      #6;
      $display("in task2");
    end
  endtask
  
  task task3();
    fork : task3_0
    forever begin
      #7;
   // disable fork task3_0 ;
      $display("disable fork before");
   // disable task3_0 ;
      disable fork ;
        $display("disable fork after");
      $display("in task3");
    end
    join
  endtask
  
  task task4();
    forever begin
      #8;
      $display("in task4");
    end
  endtask
  
  initial begin
   fork : name
      task1();
      task2();
      task3();
      task4();
    join
  end
  
  initial begin
    #60;
    $finish;
  end
  
endmodule

```

As per my understanding after disabling the fork in task3 it should not print the messages from task3. But it is not the scenario what i was getting in simulation.

Thanks & Regards,  
Shriramvaraprasad B.

---

<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:** [December 7, 2016, 3:46pm UTC](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662/23 "2016-12-07T15:46:00Z")

</div>

_In reply to [SHRI12326](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662/22):_  
I’ll repeat this for the third time here.

> The **disable fork** statements kills the _children_ of the currently running thread. (i.e the thread executing the **disable fork** statement).

The thread where you execute the **disable fork** has no children. The fork/join you put inside task3 creates a child thread, but the disable is executed from the child. You can use a **break** statement to get out of your forever loop instead of the disable. Then there is no need for the fork inside task3.

---

<div class="post-metadata">

**Author:** ![ChinnalaSomeswaraRao](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/f4b2a3/32.png) [@ChinnalaSomeswaraRao](https://verificationacademy.com/forums/u/ChinnalaSomeswaraRao)\
**Post date:** [July 23, 2021, 3:21pm UTC](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662/24 "2021-07-23T15:21:45Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662/23):_

Hi Dev,

I have a code where disable fork is not working.

```verilog
        initial begin
             .....
             .....
            //flip enable stage
            fork : fork_flip_en_chk
                begin
                    @(posedge calib_flip_en);
                end
                begin
                    #500ns; //TODO confirm the wait time
                    `uvm_error("COARSE_CAL_CHK", "calib_flip_en is not asserted within 500ns of completion of phase0 code sweep")
                end
            join_any
            disable fork_flip_en_chk;
            ....
        end

```

In the above code disable fork is not worked. In my simulation calib\_flip\_en posedge occurred much before 500ns wait time. But still I got the uvm\_error. Am I doing anything fundamentally wrong?

Thanks in advance…

---

<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 23, 2021, 3:44pm UTC](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662/25 "2021-07-23T15:44:35Z")

</div>

_In reply to [Somesh Chinnala](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662/24):_

I believe you have a tool bug. Can you use **disable fork** instead?

---

<div class="post-metadata">

**Author:** ![ChinnalaSomeswaraRao](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/f4b2a3/32.png) [@ChinnalaSomeswaraRao](https://verificationacademy.com/forums/u/ChinnalaSomeswaraRao)\
**Post date:** [July 24, 2021, 8:10am UTC](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662/26 "2021-07-24T08:10:41Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662/25):_

Thanks Dev. Just disable fork worked without using block naming.  
-Somesh Chinnala

[Previous page](https://verificationacademy.com/forums/t/confusion-in-fork-join-disable-fork/28662.md?page=1)
