Meyers singleton and dynamic libraries

Does Meyers Singleton work in a dynamic library script?
That is, one library that defines a singleton, others that use it, each in its own compilation unit?
(I suppose this doesn't matter, but the specific architecture is an OS X framework application)

I use the Vanilla Meyers Singleton template: The following method is Instance()defined in the line in the header file for the utility class (which is defined in the dynamic library):

    static Logger&  Instance()
              {
                 static Logger singletonInstance;
                 return singletonInstance;
              }

The copy constructor is both operator=declared private and not implemented, so we have to be good, right?

Now, if I link this library defining a singleton from the main application, I see that the constructor is called several times .. with different addresses for thisand all the oddities that I would expect when not with the actual singleton, but with multiple instances of the class.

So, I am wondering if the dynamic library approach forces the singleton Meyers to be fixed, or does each compilation unit — the library, the main application — include a header for singleton (effectively declaring and defining an instance ()) will get a “Singleton's own instance”?

In fact, I'm not quite sure what to do with my observations, so any hints were highly appreciated!

+4
1

Instance , ( , Logger). static. , Instance , .

, , . , , Instance , , static Logger Instance.

Instance inline, , ( , dylib). , inline, , , ( ), dylib ( ).

, , .

, , ++ 11. , ++ 98/03, ++ 11 . OS X ++ 03 .

: Instance() atexit ( ), , singletonInstance Instance(), undefined. atexit(), Instance(), . . , :

Logger&  Instance()
{
   static Logger* singletonInstance = new Logger;
   return *singletonInstance;
}

, (, , ), .

+9

Source: https://habr.com/ru/post/1524376/