Boost logo

Boost :

Subject: Re: [boost] [lockfree] review
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2011-08-24 14:14:02


Dave Abrahams wrote:
>
> on Tue Aug 23 2011, Alexander Terekhov <terekhov-AT-web.de> wrote:
>
> > Dave Abrahams wrote:
> >
> > [... memory model ...]
> >
> >> It's not really different than locking. If you want to write to shared
> >> data, you need some way of making it not-a-race. It's just that when
> >> the data structure is small enough (like an int) you can make it atomic
> >> instead of putting a lock around it.
> >
> > No.
>
> 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.

regards,
alexander.


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