VLSI DV Interview Puzzles · All levels

Competing Active Writers on x

Predict post-NBA values of x and y on each edge. Is behavior deterministic across simulators?

Puzzle

Difficulty: Medium · Puzzle 1 of 6 · Topic: Race Condition Puzzles

Predict post-NBA values of x and y on each edge. Is behavior deterministic across simulators?

Code

systemverilog
module tb;
  bit clk = 0;
  int x = 0;
  int y = 0;

  always #5 clk = ~clk;

  always @(posedge clk) begin
    x = x + 1;
    y <= x;
  end

  always @(posedge clk) begin
    x = x + 10;
  end

  initial begin
    repeat (2) begin
      @(posedge clk);
      $strobe("[%0t] x=%0d y=%0d", $time, x, y);
    end
    $finish;
  end
endmodule

Hint

Both blocks write x in active with no ordering guarantee.

Step-by-step solution

diagram
1) x ends each edge as old_x + 11 regardless of order.
2) y<=x samples x in whichever intermediate active state Process A sees.
3) If A runs first on first edge, y becomes 1; if B runs first, y becomes 11.
4) Same ambiguity repeats each edge, so y is race-dependent.

Answer

Answer: x is deterministic per edge (+11), but y is nondeterministic because it samples race-dependent active-state x before NBA update.

Why candidates get it wrong

Using NBA on y does not sanitize the active-region race on x.

Interviewer follow-up

How would you refactor to a single writer while preserving intended math?

Related topics