Platform SDK: DLLs, Processes, and Threads

InterlockedExchangePointer

The InterlockedExchangePointer function atomically exchanges a pair of values. The function prevents more than one thread from using the same variable simultaneously.

If you are exchanging pointer values, this function supersedes the InterlockedExchange function.

PVOID InterlockedExchangePointer(
  PVOID *Target,  // value to exchange
  PVOID Value     // new value
);

Parameters

Target
[in/out] Pointer to the pointer to the value to exchange. The function sets the value to Value.
Value
[in] Specifies a new value for Target.

Return Values

The function returns the initial value pointed to by Target.

Remarks

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.

Requirements

  Windows NT/2000: Requires Windows NT 3.5 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.

See Also

Synchronization Overview, Synchronization Functions, Interlocked Variable Access, InterlockedCompareExchange, InterlockedCompareExchangePointer, InterlockedDecrement, InterlockedExchange, InterlockedExchangeAdd, InterlockedIncrement