Question about disable fork, children and grandchildren

Hi,

I have the following code with disable fork.

module parallel_threads;


    initial begin
    
       fork begin   // Main fork              
         
         fork    // child fork
           fork   // grandchild fork
             
             #10$display("inside inside...", $time);
             #20$display("inside inside...", $time);
       
           join_none
          
           #10 $display("Thread 1 line1...", $time);
           $display("Thread 1 line2...", $time);
           
         join_none
         
         fork
       
           $display("Thread 2 line1...", $time);
           $display("Thread 2 line2..", $time);
      
         join_none
         
         fork    
          
           #1 $display("Thread 3 line1...", $time);
           #1 $display("Thread 3 line2.", $time);
      
         join_none
       end
       join
      
      $display("came out of join", $time);
      disable fork;  
      $display("disable", $time);
      #100;
     
     end
    
      initial begin
      #250;
        $display($time,"\t sim ending\n");
      $finish;
     end
    
  endmodule

Here, the disable fork is outside of the main fork. If my understanding is right, the disable fork will disable the main fork. But the main fork has 3 child forks and also 1 grandchild forks. why do I see that these are also disabled?

This is the output that I see:
came out of join 0
disable 0
250 sim ending

Hi,

It’s possible that the expected behaviour you are seeing is due to the “join_none” that are used. All child processes end up getting killed when the “disable_fork” is called.

A related thread :

https://verificationacademy.com/forums/systemverilog/confusion-fork-join-…-disable-fork

In reply to KillSteal:

Also note that there are race conditions here. Any of the three $display statements could begin execution as soon as hitting the join from the main fork. But all of the other descendent thread will be killed.