<Previous
Page Next>
The fork...join
construct enables the creation of concurrent processes from each of its
parallel statements.
The syntax to declare a fork...join
block is:
type_of_block @(sensitivity_list)
fork
statement1;
statement2;
----
join
//Sensitivity_list
is optional.
One or more statements can be
specified, each statement shall execute as a concurrent process.
A Verilog fork...join
block always causes the process executing the fork statement to block
until the termination of all forked processes. With the addition of the
join_any and join_none keywords, SystemVerilog provides three
choices for specifying when the parent (forking) process resumes
execution. Declaration of fork...join_none and fork...join_any are similar
to fork...join.
fork....join control options:
Option |
Description |
join |
The parent process blocks until all
the processes spawned by this fork complete. . |
join_any |
The parent process blocks until any
one of the processes spawned by this fork complete. |
join_none |
The parent process continues to execute concurrently
with all the processes spawned by the fork. The spawned processes do
not start executing until the parent thread executes a blocking
statement. |
When defining a fork...join
block, encapsulating the entire fork within a begin...end
block causes the entire block to execute as a single process, with
each statement executing sequentially.
fork
begin
statement1; //one process with 2
statements
statement2;
end
join |
Consider the example below.
initial
begin
clk = 0;
#5;
fork
#5 a = 0;
#10 b = 0;
join
clk = 1;
end
//clk becomes 1 when //time=20 |
initial
begin
clk = 0;
#5;
fork
#5 a = 0;
#10 b = 0;
join_any
clk = 1;
end
//clk becomes 1 when //time=10 |
initial
begin
clk = 0;
#5;
fork
#5 a = 0;
#10 b = 0;
join_none
clk = 1;
end
//clk becomes 1 when //time=5 |
In the following example, two
processes are forked, the first one waits for 20ns and the second waits
for the named event eventA to be triggered. Because the join
keyword is specified, the parent process shall block until the two
processes complete; That is, until 20ns have elapsed and event A has been
triggered.
fork
begin
$display( "First
Block\n" );
# 20ns;
end
begin
$display( "Second Block\n" );
@eventA;
end
join |
A return statement within the context of a fork...join statement is illegal and shall result in a compilation error. For
example:
task wait_20;
fork
# 20;
return ; // Illegal: cannot
return; task lives in another process
join_none
endtask |
Automatic variables declared in
the scope of the fork�join block shall be initialized to the
initialization value whenever execution enters their scope, and before any
processes are spawned. These variables are useful in processes spawned by
looping constructs to store unique, per-iteration data. For example:
initial
for( int j =
1; j <= 3; ++j )
| |