简体   繁体   中英

How to solve the global variable problem of shared module?

I'm learning about dynamic links recently. Suppose I have a.so file with a global variable called global. If this.so file is used in prog1 and prog2, how can prog1 and prog2 have different copies of the global variable? If the.so file also needs to use the global variable, how does it use different copies of prog1 and prog2?

A global variable is a single instance of a variable that is globally accessible within the addressable memory local to each executing process (program).

If there are multiple instances of the same program executing, or those programs share a common library, they will still have their own local memory which includes an area for global variables. So each program has its own global variables that are not shared with other processes. Therefore there is no clash between the programs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM