The InterlockedCompareExchangeToUser function performs an atomic compare-and-exchange operation on a 32-bit value in user-mode memory.
Syntax
LONG InterlockedCompareExchangeToUser(
  LONG volatile *Destination,
  LONG          ExChange,
  LONG          Comperand
);
Parameters
Destination
[in, out]指向包含目标值的用户模式内存位置的指针。 The pointer must be naturally aligned for the data type; that is, the memory location must be 4-byte aligned since Destination points to a 4-byte type.
ExChange
[in]交换值。
Comperand
[in] The value to compare to Destination.
Return value
The function returns the initial value of the Destination parameter.
Remarks
联锁函数提供了一种简单的机制,用于同步对多个线程共享的变量的访问。 对于对其他互锁函数的调用,此函数是原子的。 它生成完整内存屏障,以确保按顺序完成内存作。
此函数在用户模式内存中提供对 32 位值的原子比较和交换访问。 The function compares the Destination value with the Comperand value. If the Destination value is equal to the Comperand value, the ExChange value is stored in the address specified by Destination. 否则,不执行任何作。
如果作失败(例如目标地址不是有效的用户模式地址或不可访问),该函数将引发结构化异常。
此函数适用于所有版本的 Windows,而不仅仅是最新版本。 You need to consume the latest WDK to get the function declaration from the usermode_accessors.h header. You also need the library (umaccess.lib) from the latest WDK. 但是,生成的驱动程序将在较旧版本的 Windows 上运行。
Requirements
| Requirement | Value | 
|---|---|
| 最低支持的客户端 | See Remarks | 
| Header | usermode_accessors.h | 
| Library | umaccess.lib | 
| IRQL | 小于或等于APC_LEVEL |