This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH][RFC] Remove volatile from data members in libstdc++
- From: Ian Lance Taylor <iant at google dot com>
- To: "Boehm, Hans" <hans dot boehm at hp dot com>
- Cc: "Richard Guenther" <rguenther at suse dot de>, "Paolo Carlini" <pcarlini at suse dot de>, <gcc-patches at gcc dot gnu dot org>, <libstdc++ at gcc dot gnu dot org>
- Date: 12 Jul 2006 18:15:27 -0700
- Subject: Re: [PATCH][RFC] Remove volatile from data members in libstdc++
- References: <65953E8166311641A685BDF71D865826C1DE72@cacexc12.americas.cpqcorp.net>
"Boehm, Hans" <hans.boehm@hp.com> writes:
> a) Tell the compiler that asynchronous changes are possible, and hence
> hopefully reduces the probability of performing transformations that are
> unsafe in their presence, and
But, as I'm sure you know, volatile doesn't really tell the compiler
that. Volatile tells the compiler that it needs to access the data
precisely as it is written. In particular volatile doesn't force the
compiler to do anything atomically, with the exception of assignments
to variables of type "volatile sig_atomic_t". If you need atomic
operations, you need to tell the compiler that, e.g., by using the
atomic builtins which gcc now provides (following icc), or by using
volatile inline asm statements with memory clobbers.
> As far as (a) is concerned, I'm also worried about more complex compiler
> transformations. For example, without the volatile declaration, in some
> circumstances it is acceptable for the compiler to read the reference
> count more than once if it has to be spilled from a register. Thus the
> same unmodified const local copy could appear to contain two different
> values in different places. I really don't want to have to reason about
> such things.
This is true. But if you implement atomic operations, which is really
what you need, then this can't happen anyhow.
Ian