0% found this document useful (0 votes)
128 views3 pages

Fork Join Combination in For Loop

This document discusses different combinations of using fork-join blocks within a for loop in Verilog code and the resulting output. It shows 11 code examples of various ways to use fork with join_none, join_any, or no join at all within a for loop, and the output produced in each case.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views3 pages

Fork Join Combination in For Loop

This document discusses different combinations of using fork-join blocks within a for loop in Verilog code and the resulting output. It shows 11 code examples of various ways to use fork with join_none, join_any, or no join at all within a for loop, and the output produced in each case.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

FORK-JOIN combinations in FOR loop (we have to extremely careful)

Combination Code Result


1 module tb;
initial time=0, i =5
begin time=0, i =5
for (int i=0; i<5; i++)
begin time=0, i =5
fork time=0, i =5
$display ("time=%0t, i =%0d”, i); time=0, i =5
join_none
end
end
endmodule
2 module tb;
initial time=0, i=5
begin
time=0, i=5
for (int i=0; i<5; i++)
begin time=0, i=5
fork time=0, i=5
#5; $display ("time=%0t, i=%0d", $time, i);
time=0, i=5
join_none
end
end
endmodule
3 module tb;
integer i;
initial time=0, i=1
begin time=0, i=2
for (i=0; i<5; i++)
time=0, i=3
begin
#0; time=0, i=4
fork time=0, i=5
$display ("time=%0t, i=%0d", $time, i);
join_none
end
end
endmodule
4 module tb;
static int j;
initial
time=0, j=5
begin
for (int i=0; i<5; i++) time=0, j=5
begin time=0, j=5
fork
time=0, j=5
j = i;
$display ("time=%0t, j=%0d", $time, j); time=0, j=5
join_none
end
end
endmodule
5 module tb;
initial
begin
time=0, j=4
for (int i=0; i<5; i++)
begin time=0, j=3
automatic int j = i; time=0, j=2
fork time=0, j=1
$display ("time=%0t, j=%0d", $time, j);
join_none time=0, j=0
end
end
endmodule
6 module tb;
initial
begin time=0, j=4
for (int i=0; i<5; i++) time=0, j=4
begin
time=0, j=4
int j;
j = i; time=0, j=4
fork time=0, j=4
$display ("time=%0t, i=%0d", $time, j);
join_none
end
end
endmodule
7 module tb;
initial time=0, j=4
begin
time=0, j=3
for (int i=0; i<5; i++)
begin time=0, j=2
fork time=0, j=1
automatic int j=i; time=0, j=0
$display ("time=%0t, j=%0d", $time, j);
join_none
end
end
endmodule
8 module tb;
initial
begin
for (int i=0; i<5; i++)
begin time=0, j=5
fork time=0, j=5
begin
time=0, j=5
automatic int j=i;
$display ("time=%0t, i=%0d", $time, j); time=0, j=5
end time=0, j=5
join_none
end
end
endmodule
9 module tb;
initial
begin
for (int i=0; i<5; i++)
begin time=0, i=0
fork time=0, i=1
begin
time=0, i=2
$display ("time=%0t, i=%0d", $time, i);
end time=0, i=3
join_none time=0, i=4
wait fork;
end
end
endmodule
10 module tb;
initial
begin
for (int i=0; i<5; i++)
begin time=0, i=0
fork time=0, i=1
begin
time=0, i=2
$display ("time=%0t, i=%0d", $time, i);
end time=0, i=3
join_any time=0, i=4
wait fork;
end
end
endmodule
11 module tb;
initial
begin
for (int i=0; i<5; i++)
begin time=0, i=0
fork time=0, i=1
begin
time=0, i=2
$display ("time=%0t, i=%0d", $time, i);
end time=0, i=3
join time=0, i=4
end
end
endmodule
EDA LINK: https://www.edaplayground.com/x/9Abt

You might also like