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 post and delve into the code in it.
In my opinion this is a kind of masterpiece about how you can strive for excellence to kill the beauty and clarity of the code and turn it into a perfect and unreadable stuffing.
My opinion is that thread safe is not needed for Singleton, as The problem of simultaneously initializing a static variable in Meyers Singleton can be solved in simpler ways.
For example, calling 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?
I advise all fans of C ++ to read this post and delve into the code in it.
In my opinion this is a kind of masterpiece about how you can strive for excellence to kill the beauty and clarity of the code and turn it into a perfect and unreadable stuffing.
My opinion is that thread safe is not needed for Singleton, as The problem of simultaneously initializing a static variable in Meyers Singleton can be solved in simpler ways.
For example, calling 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?