📜 ⬆️ ⬇️

Atomically thread-safe Meyers singleton implementation

I read the last topic about Singleton in this group “Perfect Code” and I remembered a recent post in the Google group comp.lang.c ++. Moderated about the perfect implementation of thread safe Singleton .
I advise all fans of C ++ to read this message and delve into the code in it.

In my opinion, this is a kind of masterpiece about how you can kill the beauty and clarity of the code with the striving for perfection and turn it into a perfect and unreadable stuffing.
My opinion is that thread safe for Singleton is not needed, because The problem of simultaneous initialization of a static variable in Meyers Singleton can be solved in simpler ways.

For example, call the instance method for this Singleton before creating the first thread that will use it, for example, at the beginning of main () or in the function that creates these threads.
')
Any objections or thoughts on this?

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


All Articles