VLSI DV Interview Puzzles · All levels

disable Named Fork Scope

Which lines print, and why does one statement after `disable` never execute?

Puzzle

Difficulty: Hard · Puzzle 4 of 6 · Topic: Fork Join Puzzles

Which lines print, and why does one statement after `disable` never execute?

Code

systemverilog
module p4;
  initial begin
    fork : outer
      begin
        #5 $display("%0t W1", $time);
        #5 $display("%0t W2", $time);
      end
      begin
        #6 disable outer;
        $display("%0t K", $time);
      end
    join
    $display("%0t DONE", $time);
  end
endmodule

Hint

`disable outer` terminates the named block and all processes inside it, including the caller process itself.

Step-by-step solution

diagram
1) Worker prints W1 at t=5.
2) At t=6, second branch executes `disable outer`, which terminates the entire named fork block.
3) Because caller is terminated by disable, statement `K` is never reached.
4) `join` returns immediately after block termination, so DONE prints at t=6.
5) W2 at t=10 never occurs.

Answer

Answer: W1@5 and DONE@6 only; W2 and K do not print

Why candidates get it wrong

Many engineers think `disable` kills siblings but lets caller continue to next statement.

Interviewer follow-up

How would behavior differ if you used `disable fork;` instead of `disable outer;` here?

Related topics