Re: Am I or Alexandrescu wrong about singletons?
On Mar 18, 10:32 pm, Joshua Maurice <joshuamaur...@gmail.com> wrote:
On Mar 17, 8:16 pm, "Leigh Johnston" <le...@i42.co.uk> wrote:
I can't recall for the life of me where I read it, but I seem
to recall Andrei admitting that he misunderstand volatile, and
learned of the error of his ways, possibly in conjunction with
"C++ And The Perils Of Double-Checked Locking".
It was in a discussion in this group, although I don't remember
exactly when. The curious thing is that Andrei's techniques
actually work, not because of any particular semantics of
volatile, but because of the way it works in the type system;
its use caused type errors (much like the one the original
poster saw) if you attempted to circumvent the locking.
The misunderstanding of volatile is apparently widespread. To
the point that Microsoft actually proposed giving it the
required semantics to the standards committee. That didn't go
over very well, since it caused problems with the intended use
of volatile. The Microsoft representative (Herb Sutter, as it
happens) immediately withdrew the proposal, but I think they
intend to implement these semantics in some future compiler, or
perhaps have already implemented them in VC10. In defense of
the Microsoft proposal: the proposed semantics do make sense if
you restrict yourself to the world of application programs under
general purpose OS's, like Windows or Unix. And the semantics
actually implemented by volatile in most other compilers, like
g++ or Sun CC, are totally useless, even in the contexts for
which volatile was designed. At present, it's probably best to
class volatile in the same category as export: none of the
widely used compilers implement it to do anything useful.
B- repeat my (perhaps unfounded) second hand information that
volatile in fact on most current implementations does not make
a global ordering of reads and writes.
Independantly of what the standard says (and it does imply
certain guarantees, such as would be necessary, for example, to
use it for memory mapped IO), volatile has no practical
semantics in most current compilers (Sun CC, g++, VC++, at least
up through VC8.0).
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]