I have one question regarding fork-join let’s say I have one automatic variable “a”. In fork-join, I have two threads in one thread “a” is incrementing, and in another thread “a” is decrementing. I am expecting the display one answer to be 3 and display 2 answer to be 1 because I am thinking each time “a” is called it will allocate memory. Can anyone correct me if my thinking is wrong.
module top;
initial
begin
automatic int a = 2;
fork
begin //: 1
a = a + 1;
$display("1 %d", a);
end
begin //: 2
a = a - 1;
$display("2 %d", a);
end
join
end
endmodule
run -all
1 3
2 2
exit
along with that what if we don’t have an automatic keyword and what is the behaviour of the code? I think it is a race condition correct me If I am wrong.
Thank You.