Suppose I have a library with a global variable which is accessed for both Read and Write operations.
I am assuming the following:
Are the assumptions above correct?
If it matters anything (although I suppose it doesn't), then I am coding in C++ and running over Windows.
Thanks
Your last assumption is wrong, you cannot accidentally share data between libraries.
How this is achieved is specific to each library format and operating system, but the main idea is simple:
int rand() { return 4; }
)"Hello, World!"
)Even when using fork
on Linux, the newly created process will not share the variables from its parent process; it will share their initial value in a copy, but both will then evolve differently.
That being said, just avoid global variables; and if possible also avoid thread-local variables.