I did a little search of old group threads, and this popped up:
http://groups.google.com/group/comp....1b524310a37e9e
The jist of it is, apparently, as the thread starter discovered, the
static construction of an object isn't an atomic operation. When it
gets compiled, it is turned into a set of instructions where a flag is
checked before the object is instantiated (which makes sense...I don't
know if the C++ Standard mentions whether it has to be done in the
certain way...I should look it up...). So if you think about it,
multiple threads could get past this check to instantiate the object,
which makes this not thread safe.
Ronen Yacov wrote:
Hi everybody,
When declaring a singleton, we write:
static CMySingle::instance()
{
static CMySingle instance;
return instance;
}
Why should there be a problem in a multithreaded enviroment?
If one thread creates a static object the other threads will have the
same
instance (becuase its static).
And if there is a problem, how the docuble check locking solves it?