CompareExchange()

Interlocked::CompareExchange(T&, T, T) method

Compare-exchanges value on variable: checks if variable is equal to specific value and stores the new value only if stored value matches expected.

template<typename T> static std::enable_if<IsSupportedInt<T>, T>::type System::Threading::Interlocked::CompareExchange(T &location1, T value, T comparand)

Template parameters

ParameterDescription
TVariable type.

Arguments

ParameterTypeDescription
location1T&Variable reference to change.
valueTValue to store.
comparandTValue to compare variable’s value to before exchanging.

Return Value

Value of variable on operation start regardless whether it was changed or not.

Interlocked::CompareExchange(T&, T, T) method

Compare-exchanges value on variable: checks if variable is equal to specific value and stores the new value only if stored value matches expected. Not implemented.

template<typename T> static std::enable_if<!IsSupportedInt<T>, T>::type System::Threading::Interlocked::CompareExchange(T &location1, T value, T comparand)

Template parameters

ParameterDescription
TVariable type.

Arguments

ParameterTypeDescription
location1T&Variable reference to change.
valueTValue to store.
comparandTValue to compare variable’s value to before exchanging.

Return Value

Value of variable on operation start regardless whether it was changed or not.

Interlocked::CompareExchange(int32_t&, int32_t, int32_t, bool&) method

Compare-exchanges value on variable: checks if variable is equal to specific value and stores the new value only if stored value matches expected.

static int32_t System::Threading::Interlocked::CompareExchange(int32_t &location1, int32_t value, int32_t comparand, bool &succeeded)

Arguments

ParameterTypeDescription
location1int32_t&Variable reference to change.
valueint32_tValue to store.
comparandint32_tValue to compare variable’s value to before exchanging.
succeededbool&Reference to variable which is set to true if exchange took place and to false otherwise.

Return Value

Value of variable on operation start regardless whether it was changed or not.

See Also