Please correct me if this is wrong, but can the same variable declared in a package be shared by multiple modules which import that package?
package p;
int x;
endpackage
module m1;
import p::*;
initial begin
x = 5;
end
endmodule
module m2;
import p::*;
initial begin
#10;
x += 3;
end
endmodule
In the above example is the final value of p::x=8?
Note that although SystemVerilog allows global shared variables in a package, having two processes concurrently accessing to them is not a generally good programming practice. Better to use a mailbox or some combination of semaphores and queues (which can sill be declared inside a common package).
Yes that’s for sure Dave-- I was just wanting to confirm that multiple modules could indeed access the same variable if they both imported the package.