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
of volatile.
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:
http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_10
[begin quote]
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:
fork()
pthread_barrier_wait()
pthread_cond_broadcast()
pthread_cond_signal()
pthread_cond_timedwait()
pthread_cond_wait()
pthread_create()
pthread_join()
pthread_mutex_lock()
pthread_mutex_timedlock()
pthread_mutex_trylock()
pthread_mutex_unlock()
pthread_spin_lock()
pthread_spin_trylock()
pthread_spin_unlock()
pthread_rwlock_rdlock()
pthread_rwlock_timedrdlock()
pthread_rwlock_timedwrlock()
pthread_rwlock_tryrdlock()
pthread_rwlock_trywrlock()
pthread_rwlock_unlock()
pthread_rwlock_wrlock()
sem_post()
sem_trywait()
sem_wait()
wait()
waitpid()
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
location simultaneously.
[end quote]
-- Ross Smith