I have the following piece of code to swap two numbers:
class Example;
function void swap(int x, int y);
int temp;
$display("Before swap: x = %0d, y = %0d", x, y);
temp = x;
x = y;
y = temp;
$display("After swap: x = %0d, y = %0d", x, y);
endfunction
endclass
module TB;
initial begin
Example E;
E = new();
fork begin
E.swap(20, 150);
E.swap(11, 22);
E.swap(55, 44);
E.swap(0,0);
end
join
end
endmodule
I expected a race condition here for the swaps (inside the fork…join) because I have NOT defined the function to be “automatic” but the result looks fine (swaps are correct!). Why is that?
I made the “swap” function automatic and swaps are correct there too.
Confused :( Any insight is greatly appreciated.