compareAndExchange(expected:desired:)
Atomically compares the value against expected
and, if they are equal, replaces the value with desired
.
This declaration is deprecated: please use ManagedAtomic from https://github.com/apple/swift-atomics instead
func compareAndExchange(expected: T, desired: T) -> Bool
Parameters
Returns
True
if the exchange occurred, or False
if expected
did not match the current value and so no exchange occurred.
This implementation conforms to C11’s atomic_compare_exchange_strong
. This means that the compare-and-swap will always succeed if expected
is equal to value. Additionally, it uses a sequentially consistent ordering. For more details on atomic memory models, check the documentation for C11’s stdatomic.h
.