I have an atomic type where I need to atomically compare it with a value, and if the two values are not equal then exchange the value of the atomic.
Put another way, where compare_exchange_strong essentially does this operation atomically:
if (atomic_value == expected)
atomic_value = desired;
...I'm looking for a way to do this:
if (atomic_value != expected)
atomic_value = desired;
(Yes, I know compare_exchange_strong compares using bitwise equality, not the == operator. And I know the value of expected gets assigned when the comparison fails. This was just for illustration purposes. In my use case I don't need the value of the atomic regardless of the result of the comparison.)
Is there any way to do this without having to fall back on using a lock instead of std::atomic?