Boost logo

Boost :

Subject: Re: [boost] [lockfree] review
From: Peter Dimov (pdimov_at_[hidden])
Date: 2011-08-25 08:03:20


Ilya Sokolov wrote:
> Here is a more correct example:
>
> int x = 0;
> int y = 0;
> int r1, r2;
> mutex mx, my;
>
> // Thread 1:
> mx.lock();
> x = 1;
> mx.unlock();
>
> my.lock();
> r1 = y;
> my.unlock();
>
> // Thread 2:
> my.lock();
> y = 1;
> my.unlock();
>
> mx.lock();
> r2 = x;
> mx.unlock();
>
> Now, it is possible that r1 == r2 == 0, ...

I don't think that it is, no matter how you reorder things.

Hans Boehm has a proof that race-free programs containing only lock/unlock
are sequentially consistent:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2392.html

I haven't looked at it in detail though. :-)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk