This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization of conditional access to globals: thread-unsafe?
- From: Tomash Brechko <tomash dot brechko at gmail dot com>
- To: Bart Van Assche <bart dot vanassche at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 26 Oct 2007 18:33:34 +0400
- Subject: Re: Optimization of conditional access to globals: thread-unsafe?
- References: <e2e108260710260541n61462585u99de9bc0617720f4@mail.gmail.com> <e2e108260710260620k2a2e21b3t1d6c052f14d36094@mail.gmail.com>
Hello Bart,
Thanks for the summary. There are good pointers in this e-mail thread
regarding the current state of the process of defining memory model
for C++ (and eventually for C I guess).
>From those pointers several conclusions may be made (which are in line
with that you said):
- though neither Standard C nor POSIX require to use volatile, it
seems like you have to use it until the memory model is clearly
defined.
- the compiler should not introduce speculative stores to the shared
objects. This is what my original question was about. I haven't
read all the papers yet, so one thing is still unclear to me: it
seems like atomic variables will be annotated as such
(atomic<int>). But I found no proposal for annotation of
non-atomic objects that are protected by the ordinary locks (like
mutexes). Will the compiler be forbiden to do all speculative
stores, or how will it recognize shared objects as such?
- the compiler should not cross object boundary when doing the store
(i.e. when storing to 8-bit char it should not store to the whole
32/64-bit word). Here's the same question about shared object
annotation.
Cheers,
--
Tomash Brechko