This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][RFC] Remove volatile from data members in libstdc++


"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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]