atomic_compare_exchange_strong¶
Warning
Deprecated since Kokkos 4.5, use atomic_compare_exchange instead.
Defined in header <Kokkos_Atomic.hpp> which is included from <Kokkos_Core.hpp>
Usage¶
bool was_exchanged = atomic_compare_exchange_strong(&obj, expected, desired);
Atomically compares the current value of obj with expected
and replaces its value with desired if equal.
The function returns true if the exchange has happened, false otherwise.
Description¶
-
template<class T>
bool atomic_compare_exchange_strong(T *ptr, std::type_identity_t<T> expected, std::type_identity_t<T> desired);¶ Atomically compares
*ptrwithexpected, and if those are bitwise-equal, replaces the former withdesired. Ifdesiredis written into*ptrthentrueis returned.if (*ptr == expected) { *ptr = desired; return true; } else return false;- Parameters:
ptr – address of the object to test and to modify
expected – value expected to be found in the object
desired – the value to store in the object if as expected
- Returns:
the result of the comparison,
trueif*ptrwas equal toexpected,falseotherwise
Deprecated since version 4.5: Prefer expected == atomic_compare_exchange(&obj, expected, desired)