[cpp-threads] Another strawman memory model proposal

Alexander Terekhov alexander.terekhov at gmail.com
Mon May 9 23:06:16 BST 2005


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?

> This is an MT version of
> 
>    f( x = ..., x, 42 )

    f((lock(l), 17), 96, (unlock(l), 42));

is also broken, or am I missing something (suppose that "l" is not a 
semaphore -- requires ownership for unlock())?

regards,
alexander.




More information about the cpp-threads mailing list