From: "Trevor Lobban" <trevor_lobban@lineone.net>
To: <gcc-help@gcc.gnu.org>
Subject: Optimizer reordering question?
Date: Wed, 22 Sep 2004 08:47:00 -0000 [thread overview]
Message-ID: <001801c4a080$d3a43a70$edea1409@killer> (raw)
Hi,
I have a question on how I can write a piece of code such that I can still
get the best performance but can also guarantee it's integrity. Below is a
simplified example of what I am try to do.
I have some data which resides in shared memory, and in order to protect
against multiple updates I use a lock, however I also need to protect
against a process dying half-way through an update. So I use code similar to
the following:
Lock(pshared);
if (pshared->UpdateInProgress)
doRecovery(pshared);
pshared->UpdatedInProgress=TRUE;
pshared->value1 = localValue1; /* The critical updates */
pshared->value2 = localValue2;
pshared->value3 = localValue3;
pshared->UpdateInProgress=FALSE;
UnLock(pshared);
If when a process gets the lock, he sees that UpdateInProgress is TRUE it
knows it has some recovery to do. However my problem is how can I protect
against the optomizer re-ordering the code. I guess I need to define the
UpdateInProgress flag as volatile, but do I also need to declare the value1,
value2 and value3 is pshared as volatile too in order to guarantee that they
don't get re-ordered with respect to the UpdateInProgress flag?
Appologies for the rather long-winded explanation, but I figured it was the
best way of explaining what I am try to achieve. Any guidance is much
appreciated.
Thanks,
Trevor
reply other threads:[~2004-09-22 8:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='001801c4a080$d3a43a70$edea1409@killer' \
--to=trevor_lobban@lineone.net \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).