Platform SDK: DLLs, Processes, and Threads |
The InterlockedCompareExchangePointer function performs an atomic comparison of the specified values parameters and exchanges the values, based on the outcome of the comparison. More than one thread cannot use the same variable simultaneously.
If you are exchanging pointer values, this function supersedes the InterlockedCompareExchange function.
PVOID InterlockedCompareExchangePointer ( PVOID *Destination, // destination address PVOID Exchange, // exchange value PVOID Comperand // value to compare );
The return value is the initial value of the destination.
On a 64-bit system, the parameters are 64 bits and must be aligned on 64-bit boundaries; otherwise, the function will fail. On a 32-bit system, the parameters are 32 bits and must be aligned on 32-bit boundaries.
The interlocked functions provide a simple mechanism for synchronizing access to a variable that is shared by multiple threads. The threads of different processes can use this mechanism if the variable is in shared memory.
The InterlockedCompareExchange function performs an atomic comparison of 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. Otherwise, no operation is performed.
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 98.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
Synchronization Overview, Synchronization Functions, Interlocked Variable Access, InterlockedCompareExchange, InterlockedDecrement, InterlockedExchange, InterlockedExchangeAdd, InterlockedExchangePointer, InterlockedIncrement