
Singleton global variable in a shared library
[ mart...@online.no ]
|
| Hi
|
| I was wondering how you can specify that a global variable instance in a
| shared
| library should be shared among all clients of that library - i.e. clients
| should share
| the same instance. (Similar to a singleton).
|
| In win32, this is achieved using a pragma like so:
|
| #pragma data_seg(".SHARED")
| std::string g_myGlobalString;
| #pragma data_seg()
|
| On Solaris, I use the GNU g++ compiler version 3.01
|
I _think_ you need to use shared memory (see man shm_open), and protect
the access to it (mutex/lock/...)
Trond