module tb;
int temp[2];
initial begin
for (int i = 0; i < 2; i++) begin
temp[i] = i;
fork
print(temp[i]);
join_none
#1;
end
end
endmodule
function void print(int a);
$display("a=%0d", a);
endfunction
Actually this code works fine.But i want same output without using #1; after join_none.
1 Like
if we try with out delay , the value will be same because threads are in race-around condition
1 Like
The problem here is with the #1
delay, each iteration of the for
loop executes with a different value of the iterator variable i
. When the delay is removed, all iterations are sharing the same loop iterator variable whose value is two by the time the print statement gets executed. See For loop inside fork join_none - #13 by dave_59
Hi @dave_59 , this is not the solution, I am looking for! I don’t want to use automatic keyword here. Just use that array and get the output as 0,1.
module tb;
int temp[2];
initial begin
fork
for (int i=0;i<2;i++)begin
temp[i]=i;
print(temp[i]); end
join_none
end
endmodule
function void print(int a);
$display("a=%0d",a);
endfunction
what about this?
What about it?
This example behaves the same if you were to remove the fork/join_none
keywords. The calls to print()
happen serially in a single process.