Boost logo

Boost :

Subject: Re: [boost] [lockfree] review
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2011-08-29 22:52:04


On Sun, Aug 28, 2011 at 2:42 PM, Dave Abrahams <dave_at_[hidden]> wrote:
>
> on Sat Aug 27 2011, Gottlob Frege <gottlobfrege-AT-gmail.com> wrote:
>
>> But without a read, there is no visible behaviour.
>
> Right.  Surely it's possible to read in this scenario without
> introducing a data race?
>
>> There is probably no such thing as "reordering" in the standard.
>
> Right.
>
>> I guess I haven't read very closely the SC parts of the standard,
>> where it talks about data races.  I concentrated on the synch-with
>> parts.
>>
>> Maybe we need a better example?
>
> In order to illustrate/understand what?  I confess to being a little
> unsure what you want to achieve.
>

Good question. I think the question at hand (or in my mind) is
whether atomic<Foo>, implemented with an internal mutex, is valid.
Given

A) the reordering of

m1.lock();
x1++;
m1.unlock();

m2.lock();
x2++;
m2.unlock();

to

m1.lock();
m2.lock();
x2++;
x1++;
m1.unlock();
m2.unlock();

and
B) that atomics are suppose to be "SC", where maybe the above
reordering doesn't seem possible (if x1 and x2 were atomics
implemented with locks),

there seems to be a disconnect.
I'm fine with the reordering, and I tend not to think about SC, so I'm
not too concerned. I'm also unsure if the standard actually says
"atomics are SC" or something equivalent, or something only close to
SC. But there may be something worth understanding better here. To
understand it with "synch-with" (the part of the standard I'm more
comfortable with) we need a read/if-statement example.

Tony

P.S. yes, I should now add an example here. But I haven't been
feeling well, so it's hard to think clearly for long enough.
Particularly about threading, which requires a clear head.


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