This is the mail archive of the
mailing list for the GCC project.
RE: Optimization of conditional access to globals: thread-unsafe?
- From: "Dave Korn" <dave dot korn at artimi dot com>
- To: "'Robert Dewar'" <dewar at adacore dot com>, "'Andrew Haley'" <aph-gcc at littlepinkcloud dot COM>
- Cc: "'Bart Van Assche'" <bart dot vanassche at gmail dot com>, <gcc at gcc dot gnu dot org>, "'Andrew Pinski'" <pinskia at gmail dot com>, "'Tomash Brechko'" <tomash dot brechko at gmail dot com>
- Date: Fri, 26 Oct 2007 16:24:04 +0100
- Subject: RE: Optimization of conditional access to globals: thread-unsafe?
- References: <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <email@example.com>
On 26 October 2007 16:15, Robert Dewar wrote:
> One problem at the language standards level is that you can't easily
> talk about loads and stores, since you are defining an as-if semantic
> model, and if you make a statement about loads and stores, any other
> sequence which behaves as if that sequence were obeyed is allowed.
Well, that's precisely the problem - specifically in the context of
memory-mapped I/O registers - that volatile was invented to solve. It may
never have been clearly defined in the formal language of the specs, but I
thought it was pretty clear in intent: the compiler will emit exactly one
machine load/store operation for any rvalue reference/lvalue assignment
(respectively) in the source, at the exact sequence point in the generated
code corresponding to the location of the reference in the source. Any other
variable may be accessed more or fewer times than is written, and may be
accessed at places other than exactly where the reference is written in the
source, subject only to the as-if rule.
Can't think of a witty .sigline today....