InterlockedCompareExchangePointer function

The InterlockedCompareExchangePointer routine performs an atomic operation that compares the input pointer value pointed to by Destination with the pointer value Comperand.


PVOID InterlockedCompareExchangePointer(
  PVOID volatile *Destination,
  PVOID          Exchange,
  PVOID          Comperand



A pointer to a PVOID value. If (Destination) = Comperand, then the routine sets (Destination) to Exchange.


Specifies the PVOID value to set (*Destination) to.


Return Value

InterlockedCompareExchangePointer returns the original value of the pointer at *Destination (that is, the value of this pointer at entry to the routine).


If Comperand is equal to *Destination, then *Destination is set to equal Exchange. Otherwise, *Destination is unchanged.

InterlockedCompareExchangePointer provides a fast, atomic way to synchronize the testing and updating of a pointer variable that is shared by multiple threads. If the input value pointed to by Destination equals the value of Comperand, the value pointed to by Destination is set to the value of Exchange.

InterlockedCompareExchangePointer is designed for speed and, typically, is implemented inline by a compiler. InterlockedCompareExchangePointer is atomic only with respect to other InterlockedXxx calls. It does not use a spin lock and can be safely used on pageable data.

The InterlockedCompareExchangePointer routine is atomic only with respect to other InterlockedXxx calls.

Interlocked operations cannot be used on non-cached memory.


Minimum supported client Available starting with Windows 2000.
Target Platform Desktop
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h, Miniport.h)
IRQL Any level

See Also