Navigation
API > API/Runtime > API/Runtime/Core > API/Runtime/Core/TAtomicBase_Basic
Description
Compares the element with an expected value and, only if comparison succeeds, assigns the element to a new value. The previous value is copied into Expected in any case.
It is equivalent to this in non-atomic terms: bool CompareExchange(T& Expected, T Value) { bool bResult = this->Element == Expected; Expected = this->Element; if (bResult) { this->Element = Value; } return bResult; }
| Name | CompareExchange |
| Type | function |
| Header File | /Engine/Source/Runtime/Core/Public/Templates/Atomic.h |
| Include Path | #include "Templates/Atomic.h" |
bool CompareExchange
(
T & Expected,
T Value
)
Whether the element compared equal to Expected.
Parameters
| Name | Remarks |
|---|---|
| Expected | The value to compare to the element, and will hold the existing value of the element after returning. |
| Value | The value to assign, only if Expected matches the element. |