
25 Aug
2011
25 Aug
'11
12:03 p.m.
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. :-)