TAtomicBase_Basic::CompareExchange

Compares the element with an expected value and, only if comparison succeeds, assigns the element to a new value.

Windows
MacOS
Linux

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Templates/Atomic.h

Include

#include "Templates/Atomic.h"

Syntax

bool CompareExchange
(
    T & Expected,
    T Value
)

Remarks

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; }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; }

Returns

Whether the element compared equal to Expected.

Parameters

Parameter

Description

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.

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.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss