Fork join

hi,

look at this below code


program abc;
 initial begin
  fork
    begin : a1
    #5;
    $display("a1"); 
    end  
    begin : a2
    #6;
    $display("a2"); 
    end  
    begin : a3
    #9;
    $display("a3"); 
    end 
   join_any
  end
endprogram

I have a doubt that, after finishing one(a1) thread i need to disable or stop the second thread(a2) and allow thread a3 to continue. can any one help me how to achive this in above code.

One way:

module abc;
 initial begin
  fork
    fork begin
        fork
          begin : a1
          #5;
          $display("a1"); 

         end  
         begin : a2
         #6;
         $display("a2"); 
         end  
       join_any
       disable fork;
    end join
    begin : a3
    #9;
    $display("a3"); 
    end 
   join_any
  end
endmodule

Another way

module abc;
 process p_a2;
 initial begin
  fork
    begin : a1
    #5;
    $display("a1"); 
    p_a2.kill();
    end  
    begin : a2
    p_a2 = process::self();
    #6;
    $display("a2"); 
    end  
    begin : a3
    #9;
    $display("a3"); 
    end 
   join_any
  end
endmodule