Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
    • Event Scheduling Puzzles
    • Race Condition Puzzles
      • Competing Active Writers on x
      • Blocking Writer vs NBA Writer Same Signal
      • Reading q Before the NBA (Not a Race)
      • Fork join_none Loop Variable Capture and kill()
      • Lost Update in Forked Counter
      • Two always_ff Writers, One Register
    • Clocking Block Puzzles
    • Semaphore & Mailbox Puzzles
    • Concurrency & Timing Puzzles: Tricky Q&A
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Race Condition Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Concurrency & Timing Puzzles
  4. Race Condition Puzzles
  5. Reading q Before the NBA (Not a Race)
On this page

    VLSI DV Interview PuzzlesAll levels

    Reading q Before the NBA (Not a Race)

    The monitor reports a mismatch although the RTL is correct. Is this a race? Give the time of every mismatch and the real cause.

    Puzzle

    Difficulty: Easy · Puzzle 3 of 6 · Topic: Race Condition Puzzles

    The monitor reports a mismatch although the RTL is correct. Is this a race? Give the time of every mismatch and the real cause.

    Code

    tb.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    `timescale 1ns/1ns
    module tb;
      bit clk = 0;
      bit d = 1;
      bit q = 0;
      always #5 clk = ~clk;
    
      always @(posedge clk) q <= d;
    
      always @(posedge clk) begin
        if (q !== d)
          $display("[%0t] mismatch q=%0b d=%0b", $time, q, d);
      end
    
      initial begin
        repeat (2) @(posedge clk);
        $finish;
      end
    endmodule

    Hint

    Both always blocks run in Active; the q update is deferred to the NBA region.

    Step-by-step solution

    Diagram
    1) At t=5 both always blocks run in Active. q<=d only queues an update, so the monitor reads the old q=0 and d=1 and prints a mismatch.
    2) The NBA region then sets q=1. This ordering is guaranteed by the LRM, so every simulator prints the same line: nothing here is a race.
    3) At t=15 q is already 1 and d is still 1, so no mismatch is printed.
    4) The bug is in the testbench: it compares q with the current d, but q holds d from the previous edge.

    Answer

    Answer: One mismatch only, at t=5 (q=0 d=1). It is deterministic, not a race; the monitor compares the wrong pair (q against the current d instead of the previous d).

    How this was checked

    Checked by running the code in Verilator 5 and Icarus Verilog 13; the printed output supports the answer above. One mismatch, at t=5: the monitor reads q before the NBA commits, which is guaranteed ordering, not a race. Icarus prints the identical single line, showing the behaviour is deterministic.

    Why candidates get it wrong

    Calling this a race teaches the wrong model: the NBA update after all Active reads is guaranteed. The mismatch disappears at t=15 only because d never changes; with a toggling d it would persist every edge.

    Interviewer follow-up

    Would using a clocking block input #0 or a $strobe-based check remove this false failure? Model answer: input #0 yes (it samples after the NBAs, so the monitor sees q=1, d=1). $strobe alone no: it only delays the print, but the if condition is still evaluated in Active with the old q. Comparing q with the previous d (or $past(d)) also fixes it.

    Say it out loud

    This is not a race. The NBA update comes after every Active read, which the LRM guarantees, so the monitor reads the old q of 0 and d of 1 at five and reports one mismatch, and every tool agrees. The trap is calling it a race, which teaches the wrong model. The bug is in the testbench, which compares q with the current d instead of the previous d; I would compare against a registered copy of d, or sample through a clocking block.

    Related topics

    • Blocking vs Nonblocking Assignments

    • The Event Scheduler & Stratified Regions

    • Anatomy of a TB/RTL Race

    • Back to Race Condition Puzzles

    • Concurrency & Timing Puzzles section

    Previous

    69 / 293

    Next: Fork join_none Loop Variable Capture and kill()

    Up next

    Up nextFork join_none Loop Variable Capture and kill()

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Competing Active Writers on x
    • Lost Update in Forked Counter
    • Two always_ff Writers, One Register