Re: Please disprove this Double-Checked Locking "fix"
On May 2, 12:23 am, Pavel
<pauldontspamt...@removeyourself.dontspam.yahoo> wrote:
James Kanze wrote:
[...]
In fact, I have never defended a Singleton pattern. IMHO it
is the most-overused, the least-understood, the
vaguest-defined of all GoF patterns; and few people seem to
have read the end of the "Consequences" sub-section of
"Singleton" section of their book (actuating Consequences #4,5
there may invalidate the whole discussion on DCL for Singleton
irrelevant).
I don't think that the presentation in the GoF was actually that
vague. The problem is that as presented in the GoF, it is a
form of contract enforcement: the design says that there may
only be one instance, so we design the class to enforce the
design. Which per se is probably overkill: the semantics of
most singletons are such that no reasonable programmer would
create more than one instance anyway, so it's not worth the
extra effort to forbid it. In the case of C++, however, the
singleton idiom is most often used primarily to solve order of
initialization issues; once you've created the code necessary to
solve those, making it a singleton (enforcing only one instance)
is merely a question of where you put the "public:".
--
James Kanze