fork/join, join_any & join_none

Running testbench activities in parallel, waiting for some or all of them, and stopping them.

A testbench does several things at once: a generator produces transactions while a driver applies them, a monitor watches the outputs and a watchdog guards against hangs. fork starts several processes in parallel; the join variant decides how long the parent waits.

Rules

for (int i = 0; i < 3; i++) fork run(i); // all three may see i = 3 join_none for (int i = 0; i < 3; i++) begin automatic int k = i; fork run(k); join_none end join_none children start after the loop finishes; they all read the shared loop variable. A per-iteration automatic copy fixes it.

How do you implement a timeout around a task that might hang?

fork run_task(); begin #TIMEOUT $error("timeout"); end join_any disable fork; — whichever finishes first ends the wait, then the other is killed.