Sie sind auf Seite 1von 4

SystemVerilog wait fork

wait fork
wait fork; causes process to block until the completion of all processes started
from fork blocks.
Example-1:
In the below example,
after the completion of Process-1 (i.e, after 5ns) fork-join_any will get unbloc
ked, $finish will get called and it ends the simulation.
Simulation will get ended in the middle of execution of process-2, this can be a
voided with the use of wait-fork.
The problem in this example is overcome in example-2 with the use of wait fork;

module wait_fork;
initial begin
$display("-----------------------------------------------------------------"
);
fork
//Process-1
begin
$display($time,"\tProcess-1 Started");
#5;
$display($time,"\tProcess-1 Finished");
end
//Process-2
begin
$display($time,"\tProcess-2 Started");
#20;
$display($time,"\tProcess-2 Finished");
end
join_any
$display("-----------------------------------------------------------------")
;
$finish; //ends the simulation
end
endmodule
Simulator output:
----------------------------------------------------------------0 Process-1 Started
0 Process-2 Started
5 Process-1 Finished
-----------------------------------------------------------------

Execute the above code on


Example-2:
In the below example,
wait fork will wait for the completion of second thread in the fork-join_any.
for better understanding compare the result of Example-1 and Example-2
module wait_fork;
initial begin
$display("-----------------------------------------------------------------"
);
fork
//Process-1
begin
$display($time,"\tProcess-1 Started");
#5;
$display($time,"\tProcess-1 Finished");
end
//Process-2
begin
$display($time,"\tProcess-2 Started");
#20;
$display($time,"\tProcess-2 Finished");
end
join_any
wait fork; //waiting for the completion of active fork threads
$display("-----------------------------------------------------------------"
);
$finish; //ends the simulation
end
endmodule
Simulator output:
----------------------------------------------------------------0 Process-1 Started
0 Process-2 Started
5 Process-1 Finished
20 Process-2 Finished
----------------------------------------------------------------SystemVerilog disable fork
disable fork
disable fork; causes process to kill/terminate all the active processes started
from fork blocks.
Example-1:
In the below example,
On execution of disable fork, all the active process will get terminated.
Process-2 of fork-1,Process-1 and Process-2 of fork-2 will get terminated.
module disable_fork;

initial begin
$display("-----------------------------------------------------------------"
);
//fork-1
fork
//Process-1
begin
$display($time,"\tProcess-1 of fork-1 Started");
#5;
$display($time,"\tProcess-1 of fork-1 Finished");
end
//Process-2
begin
$display($time,"\tProcess-2 of fork-1 Started");
#20;
$display($time,"\tProcess-2 of fork-1 Finished");
end
join_any
//fork-2
fork
//Process-1
begin
$display($time,"\tProcess-1
#5;
$display($time,"\tProcess-1
end
//Process-2
begin
$display($time,"\tProcess-2
#20;
$display($time,"\tProcess-2
end
join_none

of fork-2 Started");
of fork-2 Finished");

of fork-2 Started");
of fork-2 Finished");

disable fork;
$display("-----------------------------------------------------------------"
);
$display($time,"\tAfter disable-fork");
$display("-----------------------------------------------------------------"
);
end
endmodule
Simulator output:
---------------------------------------------------------------0 Process-1 of fork-1 Started
0 Process-2 of fork-1 Started
5 Process-1 of fork-1 Finished
---------------------------------------------------------------5 All Processes started from fork block are finished
----------------------------------------------------------------

Execute the above code on


Example-2:
In the below example,
sub_process started from process-2 will get terminated during execution of disab
le fork.
module disable_fork;
initial begin
$display("-----------------------------------------------------------------"
);
fork
//Process-1
begin
$display($time,"\tProcess-1 of fork-1 Started");
#5;
$display($time,"\tProcess-1 of fork-1 Finished");
end
//Process-2
begin
sub_process();
end
join_any
disable fork;
$display("-----------------------------------------------------------------"
);
$display($time,"\tAfter disable-fork");
$display("-----------------------------------------------------------------"
);
end
//Sub-Process
task sub_process;
$display($time,"\tSub-Process Started");
#10;
$display($time,"\tSub-Process Finished");
endtask
endmodule
Simulator output:
---------------------------------------------------------------0 Process-1 of fork-1 Started
0 Sub-Process Started
5 Process-1 of fork-1 Finished
---------------------------------------------------------------5 After disable-fork
---------------------------------------------------------------10 Sub-Process Finished

Das könnte Ihnen auch gefallen