Confusion in fork join ... disable fork

In reply to desaivs1994:
As I said above, Calling a task or function does not create a new thread; only a fork can do that. So whether a disable is “inside” a task has no relevance - it’s the thread that matters.

Hi Dave,

Can you please explain the below code.

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.

In reply to SHRI12326:
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.

In reply to dave_59:

Hi Dev,

I have a code where disable fork is not working.

        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…

In reply to Somesh Chinnala:

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

In reply to dave_59:

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