DescriptionQ774
Q774DVASIC interview problem
Capture per-iteration values in fork...join_none
TechniquesDVSystemVerilogfork joinAutomatic lifetimeConcurrency
DifficultyMedium
TopicTestbench Concurrency
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
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.
Starting declarationSystemVerilog
for (int i = 0; i < 3; i++) fork
// child print
join_none
wait fork;Example input and output
Use this case to check your interpretationInput
three iterations spawn three join_none childrenOutput
one legal print order is 0, 2, 1Explanation
The captured multiset is deterministic, but sibling scheduling is not, so any permutation of 0, 1, and 2 is legal.
02
Requirements (4)
- Print exactly one occurrence of each value 0, 1, and 2.
- Capture i in an automatic variable declared in the fork scope for that iteration.
- Wait for every spawned child before the parent finishes.
- Do not assert any particular ordering among sibling processes.
