[cpp-threads] Does pthread_mutex_lock() have release emantics?

Peter Dimov pdimov at mmltd.net
Sat May 7 00:49:33 BST 2005


Boehm, Hans wrote:
>> From: Peter Dimov
>>
>> A memory model that requires fully-fenced (even on failure)
>> synchronization
>> primitives and fully-fenced atomic operations... is not a
>> good idea. :-)
>
> I think the pthreads-like model actually doesn't.  It is stated
> that way, but I think acquire end up being sufficient for an
> atomic load and release for an atomic store (provided atomic
> operations themselves are sequentially consistent).

This is the x86 memory model - load_acq, store_rel, and every 
read-modify-write operation is fenced. Inefficiency briefly aside, consider:

X = 0, Y = 0

// thread 1

atomic_store X, 1
r1 = atomic_load Y

// thread 2

atomic_store Y, 1
r2 = atomic_load X

Sequential consistency says that r1 = 0, r2 = 0 is impossible. But it's 
possible under the x86 model.

[...]

> Even if we go with a more Java-like model, I think it's critical
> to understand this, since it affects which pthreads programs
> we will be breaking.

In theory or in practice? In practice, I bet on "none". :-) Plus, if we 
define a weaker memory model, an implementation can strengthen it as a 
conforming extension, so by defining a weaker memory model we don't actually 
break any programs. 





More information about the cpp-threads mailing list