Semantics of VarHandle CAS methods
martinrb at google.com
Wed Jul 6 03:12:58 UTC 2016
On Thu, Jun 30, 2016 at 10:54 AM, Hans Boehm <hboehm at google.com> wrote:
> On Thu, Jun 30, 2016 at 7:59 AM, Martin Buchholz <martinrb at google.com>
> > One concrete proposal that removes a method:
> > Replace
> > weakCompareAndSetAcquire and weakCompareAndSetRelease with
> > weakCompareAndSetAcquireRelease
> Using standard implementation recipes, the AcquireRelease version is
> more expensive on Power and ARM, and there are many cases (e.g.
> lock acquisition or lock release) where you only need one. I'd be
> hesitant to do that.
You've mostly convinced me.
The C++ standard is not entirely clear on this, but a cas with m_o_release
does a relaxed read, and similarly cas with m_o_acquire does a relaxed
write, corresponding to our weakCompareAndSetRelease
Let's see if I can argue against my own
you usually read the old value before the cas, and if you want the acquire,
you generally want it then!
So the natural sequence would be:
r1 = x.getAcquire();
r2 = f(r1); // reads through r1
More information about the core-libs-dev