Optimization of conditional access to globals: thread-unsafe?

Robert Dewar dewar@adacore.com
Fri Oct 26 15:18:00 GMT 2007


Andrew Haley wrote:

> Hmmm.  This is an interesting idea, but it sounds to me as though it's
> somewhat at variance with what is proposed by the C++ threads working
> group.  In any case, gcc will certainly implement whatever the
> standards committees come up with, but that is probably two years
> away.

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. In
the absence of a notion of threads at the semantic level it's difficult
to say what you mean in a formal way. In the Ada standard, we get
around this problem by having sections called "implementation advice",
which in practice are treated as requirements, but we can use language
that is not formally sound, even though everyone knows what we mean.
Of course in Ada there is a clear notion of threads semantic, and
a clear definition of what the meaning of code is in the presence
of threads, so the specific situation discussed here is easy to
deal with (though Ada takes the view that unsychronized shared access to
non-atomic or non-volatile data from separate threads has undefined
effects).



More information about the Gcc mailing list