C Linux: Global variable located in shared library as singleton

后端 未结 3 1883
醉梦人生
醉梦人生 2021-02-15 16:43

Is it possible to use global variable located in a shared library (.so) as a singleton if the library is used by more than one process?

As example the initial value is 0

3条回答
  •  星月不相逢
    2021-02-15 17:16

    Processes each live in their own memory space. (Imagine the havoc you could wreak on a machine if you could, just by loading a library that some other process is using, completely arbitrarily trash their address space!) So, globals are global, but only within a process.

提交回复
热议问题