_InterlockedExchange

9/7/2007

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

Syntax

LONG InterlockedExchange(
  LONG volatile* Target,
  LONG Value
);

Parameters

  • Target
    [in, out] Pointer to the value to be exchanged. The function sets this variable to Value, and returns its prior value.
  • Value
    [in] Value to be exchanged with the value pointed to by Target.

Return Values

The function returns the initial value of the target.

Remarks

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 variable pointed to by the Target parameter must be aligned on a 32-bit boundary; otherwise, this function will fail on multiprocessor x86 systems and any non-x86 systems.

This function should not be used on memory allocated with the PAGE_NOCACHE modifier.

Requirements

Routine Required header Architecture

_InterlockedExchange

<winnt.h>

MIPS16, MIPSII, MIPSIII, MIPS IV, MIPS 32

See Also

Reference

Intrinsic Functions for MIPS Microprocessors