Hi all,
When I use a loop in a module and declare a variable a within a fork...join_none, that variable should have a static lifetime, and its scope should be limited to the fork...join_none.
initial begin
repeat(2) begin
fork
int a;
begin
a++;
$display("a is %0d", a);
end
join_none
end
wait fork;
end
As I understand it, a new fork...join_none should be created for each iteration of the loop. Therefore, the two loops in the snippet above create two fork...join_none instances, and variable a should be initialized in both of them. Consequently, a should ultimately print 1 in both cases, but in reality, it prints 1 and 2.
Later, I tried a serial fork...join_none, and this time the results were as expected—both were 1. Why is that?
initial begin
fork
int a;
begin
a++;
$display("a is %0d", a);
end
join_none
fork
int a;
begin
a++;
$display("a is %0d", a);
end
join_none
wait fork;
end
It seems that the two fork...join_none instances of repeat are sharing the same variable.
BR