|
Boost : |
Subject: Re: [boost] [lockfree] review
From: Ilya Sokolov (ilyasokol_at_[hidden])
Date: 2011-08-25 09:27:00
On Thu, 25 Aug 2011 18:19:48 +0600, Alexander Terekhov <terekhov_at_[hidden]>
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk