Disable fork killing non current process threads

module top;
  
  initial begin:i1
    fork:f3
      #10 $display("pkt_interrupt handler");
    join_none
    $display("getting the packet");
    t1();
    
  end
  
  task t1();
    fork 
      begin:a1
        #1 $display("get preamble");
      end
	
      begin:a2
        #2 $display("get header");
      end
      
    join_none
      fork
      begin:a3
        #5 $display("get payload");
      end
      
      begin:a4
        #6 $display("get packet_timeout");
      end
		
      join_any
    
    disable fork;
      $display("Processing packet");

      
      
  endtask
  
  
endmodule

This code prints

# getting the packet
# get preamble
# get header
# get payload
# Processing packet

Why is the disable fork killing the fork f3 as well? Shouldn’t it only disable the threads spawned by the process which executed disable fork which is task t1()?

The disable fork statement kills all child processes of the parent process executing the statement. A task/function call does not create a new process.

You need to add another fork process to prevent from killing f3 fork process.

  initial begin:i1
    fork:f3
      #10 $display("pkt_interrupt handler");
    join_none
    $display("getting the packet");

    fork : guard_fork  // <=======
      t1();
    join               // <=======

  end

Refer to the following link.

Can we also give a name to each of the fork, and disable only the intended fork by calling its name?

Ex: fork: ABC
join_none

disable ABC;

That works sometines. The problem with disabling by name is that the scope name of the block is static. If there are many activations of the task, or in a loop, the disable applies to all activations.

2 Likes