1. fork...join (Wait for ALL)
Waits for ALL spawned processes to complete before continuing:
initial begin
$display("[%0t] Starting parallel tasks", $time);
fork
// Process 1
begin
#10 $display("[%0t] Process 1 done", $time);
end
// Process 2
begin
#20 $display("[%0t] Process 2 done", $time);
end
// Process 3
begin
#15 $display("[%0t] Process 3 done", $time);
end
join // Waits for ALL three processes
$display("[%0t] All processes complete!", $time);
end
// Output:
// [0] Starting parallel tasks
// [10] Process 1 done
// [15] Process 3 done
// [20] Process 2 done
// [20] All processes complete!
2. fork...join_any (Wait for FIRST)
Continues as soon as ANY ONE process completes:
initial begin
fork
begin
#10 $display("[%0t] Fast process done", $time);
end
begin
#100 $display("[%0t] Slow process done", $time);
end
join_any // Continues after FIRST one finishes
$display("[%0t] At least one process done!", $time);
disable fork; // Kill remaining processes
end
// Output:
// [10] Fast process done
// [10] At least one process done!
3. fork...join_none (Don't Wait)
Spawns processes and immediately continues - doesn't wait at all:
initial begin
$display("[%0t] Before fork", $time);
fork
begin
#10 $display("[%0t] Background process done", $time);
end
join_none // Doesn't wait at all!
$display("[%0t] Immediately after fork", $time);
#20;
$display("[%0t] End of test", $time);
end
// Output:
// [0] Before fork
// [0] Immediately after fork
// [10] Background process done
// [20] End of test