System::Threading::Interlocked::CompareExchange 方法

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

比较交换变量的值:检查变量是否等于特定值,仅在已存储的值匹配预期时才存储新值。

static int32_t System::Threading::Interlocked::CompareExchange(int32_t &location1, int32_t value, int32_t comparand, bool &succeeded)
参数类型描述
location1int32_t&用于更改的变量引用。
int32_t要存储的值。
comparandint32_t在交换前用于比较变量值的值。
成功bool&变量的引用,如果交换发生则设为 true,否则设为 false。

ReturnValue

操作开始时变量的值,无论是否已更改。

另见

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

比较交换变量的值:检查变量是否等于特定值,仅在已存储的值匹配预期时才存储新值。

template<typename T> static std::enable_if<IsSupportedInt<T>, T>::type System::Threading::Interlocked::CompareExchange(T &location1, T value, T comparand)
参数描述
T变量类型。
参数类型描述
location1T&用于更改的变量引用。
T要存储的值。
comparandT在交换前用于比较变量值的值。

ReturnValue

操作开始时变量的值,无论是否已更改。

另见

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

比较交换变量的值:检查变量是否等于特定值,仅在已存储的值匹配预期时才存储新值。未实现。

template<typename T> static std::enable_if<!IsSupportedInt<T>, T>::type System::Threading::Interlocked::CompareExchange(T &location1, T value, T comparand)
参数描述
T变量类型。
参数类型描述
location1T&用于更改的变量引用。
T要存储的值。
comparandT在交换前用于比较变量值的值。

ReturnValue

操作开始时变量的值,无论是否已更改。

另见