C++11 has a 'compare and exchange' operation for atomic variables.
The semantics are:
Atomically compares the value pointed to by
obj
with the value pointed to byexpected
, and if those are equal, replaces the former withdesired
(performs read-modify-write operation). Otherwise, loads the actual value pointed to byobj
into*expected
(performs load operation).
I want to do the same, but instead of setting *obj
when the values are equal, I want it to be set when one is greater-than the other (assume we're talking about an ordered type).
Is this supported somehow? Achievable by some hack perhaps?
Note: A CAS loop will not do for me, since both the values I'm comparing might change between non-atomic operations.