[cpp-threads] Does pthread_mutex_lock() have release emantics?
Alexander Terekhov
alexander.terekhov at gmail.com
Fri May 6 21:48:12 BST 2005
On 5/6/05, Boehm, Hans <hans.boehm at hp.com> wrote:
[...]
> Thread 1:
>
> <Do some initialization stuff>
> pthread_mutex_lock(&l)
> <continue running, never releasing lock>
>
> Thread 2:
>
> while (pthread_mutex_trylock(&l)==0) unlock(&l);
> <continue running, with knowledge that initialization by
> thread 1 was complete.>
>
> For this to work, the pthread_mutex_lock() call must have RELEASE
Whatever. Imagine that pthread_mutex_lock() is fully-fenced. "For
this to work,"
the pthread_mutex_trylock(&l)!=0. must have ACQUIRE.
And THAT is not the case even in the current (pretty busted***)
version of XBD 4.10.
http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_10
"Unless explicitly stated otherwise, if one of the above functions
returns an error,
it is unspecified whether the invocation causes memory to be synchronized."
http://www.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_trylock.html
"The pthread_mutex_trylock() function shall return zero if a lock on
the mutex object
referenced by mutex is acquired. Otherwise, an error number is
returned to indicate
the error."
And it says nothing about msync in the "otherwise" case.
regards,
alexander.
***) http://www.decadentplace.org.uk/pipermail/cpp-threads_decadentplace.org.uk/2005-April/000222.html
More information about the cpp-threads
mailing list