This is the mail archive of the
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: <firstname.lastname@example.org> <email@example.com>
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
- 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