Re: [RFC PATCH 1/1] remove redundant compare, cmpxchg already does it
From: Peter Zijlstra
Date: Fri Jun 06 2014 - 03:01:22 EST
On Thu, Jun 05, 2014 at 11:08:23AM -0700, Davidlohr Bueso wrote:
> I knew I had formally read this technique somewhere:
> http://pdos.csail.mit.edu/6.828/2010/readings/mcs.pdf (part 2.1).
>
> Peter, what do you think of adding a new cmp_cmpxchg() or dcmpxchg()
> call for such scenarios?
Don't like dcmpxchg(), too easy to confuse with double-cmpxchg or
somesuch.
That said, I'm not entirely sure we want this primitive, the thing is,
people might use it ;-)
And its somewhat dangerous in that it explicitly does not provide any
kind of memory barrier on the fail path, where cmpxchg() is an
unconditional full memory barrier.
Also, you really don't want to use it in loops.
So I think it makes more sense to leave things as are and simply apply
the pattern where safe and meaningful.
Attachment:
pgp9zy1Dj83TF.pgp
Description: PGP signature