This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with reordering of memory accesses
- To: Michael Schwingen <michaels at stochastik dot rwth-aachen dot de>
- Subject: Re: Problem with reordering of memory accesses
- From: Geoff Keating <geoffk at cygnus dot com>
- Date: 17 Oct 2000 09:51:34 -0700
- CC: gcc at gcc dot gnu dot org
- References: <20001017140250.A10784@draco.stochastik.rwth-aachen.de>
Michael Schwingen <michaels@stochastik.rwth-aachen.de> writes:
> How do I ensure that the writes occur in the specified order?
>
> Declaring x2 and x4 "volatile" helps in this test case, but not in my real
> (more complex) code. Declaring the pointer volatile seems to work, but I
> would like to use some construct that is *guaranteed* to work even with
> newer compiler versions. Is the solution with the volatile pointer safe? If
> not, what alternatives can I use?
'volatile' should be the solution you need. If you declare everything
whose ordering you care about 'volatile', then those variables should
be changed in the exact order you specify. If not, it's a bug.
In the particular case you had, declaring the pointer 'volatile' would
not reliably work. For instance, if you wrote
a->b = 3;
a->c = 4;
then what GCC can do is read 'a' twice, and then write to c and then
write to b. I don't think it would ever do this, but it could.
--
- Geoffrey Keating <geoffk@cygnus.com>