InterlockedExchangePointer function (Windows)

Switch View :
ScriptFree
InterlockedExchangePointer function

Applies to: desktop apps only

Atomically exchanges a pair of addresses.

Syntax

PVOID __cdecl InterlockedExchangePointer(
  __inout  PVOID volatile *Target,
  __in     PVOID Value
);

Parameters

Target [in, out]

A pointer to the address to exchange. The function sets the address pointed to by the Target parameter (*Target) to the address that is the value of the Value parameter, and returns the prior value of the Target parameter.

Value [in]

The address to be exchanged with the address pointed to by the Target parameter (*Target).

Return value

The function returns the initial address pointed to by the Target parameter.

Remarks

This function copies the address passed as the second parameter to the first and returns the original address of the first.

On a 64-bit system, the parameters are 64 bits and the Target parameter must be aligned on 64-bit boundaries; otherwise, the function will behave unpredictably. On a 32-bit system, the parameters are 32 bits and the Target parameter 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. This function is atomic with respect to calls to other interlocked functions.

This function is implemented using a compiler intrinsic where possible. For more information, see the WinBase.h header file and _InterlockedExchangePointer.

This function generates a full memory barrier (or fence) to ensure that memory operations are completed in order.

Itanium-based systems:  For performance-critical applications, use InterlockedExchangePointerAcquire instead.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

WinBase.h (include Windows.h)

See also

Interlocked Variable Access
InterlockedCompareExchangePointer
InterlockedExchange
InterlockedExchangeAdd
InterlockedExchangePointerAcquire
Synchronization Functions

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Community Content

GeoRanger
This function is reimplemented in <atlconv.h>, but the reimplementation is declared incorrectly.
The header file <atlconv.h> reimplements this function if _M_IX86_ is defined, but the declaration is missing the "volatile" qualifier on the first parameter (using "void **" instead of "void * volatile *").  This is in Visual Studio 2010 SP 1.  This forces you to use const_cast to remove the volatile qualifier when calling this function, otherwise the calling code won't compile.

Angus Comber
Documentation error
Minimum supported client Windows XP Minimum supported server Windows Server 2003 Are both totally incorrect. this function has been available since Windows NT 3.5, possibly earlier.