Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Capture per-iteration values in fork...join_none

Hardware interview practice

Capture per-iteration values in fork...join_none

MediumTestbench ConcurrencySystemVerilog

A loop spawns three join_none children. Correct the code so each child prints its own iteration value, then state what output ordering is and is not guaranteed.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

for (int i = 0; i < 3; i++) fork
  // child print
join_none
wait fork;
Reviewed example

Work through one case

Input
three iterations spawn three join_none children
Expected output
one legal print order is 0, 2, 1

The captured multiset is deterministic, but sibling scheduling is not, so any permutation of 0, 1, and 2 is legal.

What to cover

Requirements

  1. Print exactly one occurrence of each value 0, 1, and 2.
  2. Capture i in an automatic variable declared in the fork scope for that iteration.
  3. Wait for every spawned child before the parent finishes.
  4. Do not assert any particular ordering among sibling processes.
Continue practicing

Related questions

Testbench ConcurrencyRace a transaction against a scoped watchdog→SystemVerilog SchedulingReason about same-region forked output order→
asic.fyi · Learn silicon end to end.info@asic.fyi