[cpp-threads] Another strawman memory model proposal

Peter Dimov pdimov at mmltd.net
Mon May 9 23:16:17 BST 2005


Alexander Terekhov wrote:
> On 5/9/05, Peter Dimov <pdimov at mmltd.net> wrote:
> [...]
>>> Thread 1:
>>> lock(l); x = ...; unlock(l)
>>> 
>>> 2 options for thread 2:
>>> Thread 2a:
>>> f((lock(l), 17), x, (unlock(l), 42));
>>> 
>>> Thread 2b:
>>> g((lock(l), r1 = x, unlock(l), r1));
>>> 
>>> There is a race between Thread 1 and Thread 2a.  There is no
>>> race between Thread 1 and Thread 2b.  We need to capture that
>>> difference, since we want the first case, but not the second,
>>> to exhibit undefined behavior.
>> 
>> The 1/2a example has undefined behavior because of Clause 5
>> paragraph 4. The scalar object x is (potentially) modified by thread
>> 1 and accessed by thread 2a without the two being separated by a
>> sequence point. 
> 
> And because in "f((lock(l), 17), x, (unlock(l), 42));" unlock() can
> fire before lock(). Oder?

That too, but it probably wasn't the point of the example. :-)




More information about the cpp-threads mailing list