Boost logo

Boost :

Subject: Re: [boost] [lockfree] review
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-08-24 16:27:11


on Wed Aug 24 2011, Alexander Terekhov <terekhov-AT-web.de> wrote:

> Dave Abrahams wrote:
>>
>> All I'm saying here is that a C++11 default atomic int is equivalent to
>> an int, coupled with an associated mutex, where accesses to the int are
>> always protected by locking the associated mutex. If you're seriously
>> disagreeing with *that*, please say explicitly on what grounds.
>
> int i; mutex mi,
> int j; mutex mj;
>
> mi.lock();
> i = 1;
> mi.unlock();
>
> mj.lock();
> j = 2;
> mj.unlock();
>
> can be transformed to
>
> multi_lock(mi, mj); // deadlock free
> j = 2;
> i = 1;
> mi.unlock();
> mj.unlock();
>
> and thus result in reodering i = 1 and j = 2.
>
> With C++11 default atomics (SC) for i and j such reodering is
> prohibited.

As it is with C++11 mutexes, IIUC. Another thread that locks the same
mutexes is not allowed to observe the write to j before the write to i.
If you have contrary evidence, please point to it.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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