
25 Aug
2011
25 Aug
'11
1:27 p.m.
On Thu, 25 Aug 2011 18:19:48 +0600, Alexander Terekhov <terekhov@web.de> wrote:>
Ilya Sokolov wrote:
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, ...
Nope, it is impossible. Same as with
// Thread 1: multi_lock(mx, my); // deadlock free r1 = y; x = 1; mx.unlock(); my.unlock();
// Thread 2: multi_lock(my, mx); // deadlock free r2 = x; y = 1; my.unlock(); mx.unlock();
Doh! Should have done that myself. Sorry for the noise