This is the mail archive of the
mailing list for the GCC project.
Re: Optimization of conditional access to globals: thread-unsafe?
Erik Trulsson wrote:
On Sun, Oct 28, 2007 at 06:06:17PM -0000, Dave Korn wrote:
As far as I know, there is no separate 'pthreads' spec apart from what is
defined in the Threads section (2.9) of the SUS (http://tinyurl.com/2wdq2u)
and what it says about the various pthread_ functions in the system interfaces
(http://tinyurl.com/2r7c5k) chapter. None of that, as far as I have been able
to determine, makes any kind of claims about access to shared state or the use
Having just been pointed to that copy of the SUS, I must agree. I can't
find anything in there saying anything at all about what is required to
safely share data between threads. If that is really so it seems 'pthreads'
are even more under-specified than I thought (and I had fairly low
expectations in that regard.)
I really hope there is something I have missed.
I think the relevant part is here:
4.10 Memory Synchronization
Applications shall ensure that access to any memory location by more
than one thread of control (threads or processes) is restricted such
that no thread of control can read or modify a memory location while
another thread of control may be modifying it. Such access is restricted
using functions that synchronize thread execution and also synchronize
memory with respect to other threads. The following functions
synchronize memory with respect to other threads:
The pthread_once() function shall synchronize memory for the first call
in each thread for a given pthread_once_t object.
Unless explicitly stated otherwise, if one of the above functions
returns an error, it is unspecified whether the invocation causes memory
to be synchronized.
Applications may allow more than one thread of control to read a memory
-- Ross Smith