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

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
    • Datatype and Bit Puzzles
    • Fork Join Puzzles
      • join vs join_any vs join_none
      • Loop Variable Capture in Detached Threads
      • wait fork Synchronization Point
      • disable Named Fork Scope
      • join_any Without Cleanup
      • Inner disable fork Does Not Kill Outer Sibling
    • Queue and Array Puzzles
    • String and Casting Puzzles
    • SystemVerilog Language Puzzles: Tricky Q&A
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • Interview Prep: Puzzle Rounds5
  • DV Puzzle Cheatsheet
Loading lesson

‹Fork Join Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. SystemVerilog Language Puzzles
  4. Fork Join Puzzles
  5. Loop Variable Capture in Detached Threads

VLSI DV Interview Puzzles · All levels

Loop Variable Capture in Detached Threads

What does this print three times, and why is it not 0,1,2?

On this page

    Puzzle

    Difficulty: Medium · Puzzle 2 of 6 · Topic: Fork Join Puzzles

    What does this print three times, and why is it not 0,1,2?

    Code

    p2.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    module p2;
      initial begin
        for (int i = 0; i < 3; i++) begin
          fork
            #1 $display("i=%0d", i);
          join_none
        end
        #2;
      end
    endmodule

    Hint

    The child runs later than loop progression. Think about what value `i` has by time #1.

    Step-by-step solution

    Diagram
    1) Each iteration spawns a detached child that waits #1 before printing.
    2) The parent loop completes all iterations in the same time slot and exits with `i == 3`.
    3) At t=1, all children evaluate `i` and see 3, so each prints the same value.

    Answer

    Answer: The output is `i=3` three times

    Why candidates get it wrong

    Candidates assume each forked branch gets a copied loop index automatically.

    Interviewer follow-up

    How do you fix it so each child prints its own index value deterministically?

    Related topics

    • Back to Fork Join Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    12 / 210

    Next: wait fork Synchronization Point

    Up next

    Up nextwait fork Synchronization Point

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • disable Named Fork Scope
    • join_any Without Cleanup
    • Inner disable fork Does Not Kill Outer Sibling