Source – SV Verification Directory
Fork Join
A thread or a process is a block of code that execute sequentially. They are created using constructs like initial blocks, always blocks, and tasks. In verification there are multiple components, such as generator, driver, monitor, etc, these components have multiple threads that need to run concurrently, allowing for parallel execution of different parts of the simulation. The fork-join construct is created to run multiple procedural threads to run in parallel. Once the fork starts to execute the threads, it will wait until all the threads are completed to proceed with the execution.
The fork … join execution is pictorially represented in the figure below.
Syntax: Fork Join
fork
// process 1
// process 2
// process 3
join
Example Code: Fork Join
module tb_fork_join;
initial begin
fork
#2 $display("t = %0t, fork 1 => process 1", $time);
#10 $display("t = %0t, fork 1 => process 2", $time);
#5 $display("t = %0t, fork 1 => process 3", $time);
join
end
initial begin
fork
#3 $display("t = %0t, fork 2 => process 1", $time);
#6 $display("t = %0t, fork 2 => process 2", $time);
#1 $display("t = %0t, fork 2 => process 3", $time);
join
end
endmodule