InterlockedExchange function

The InterlockedExchange routine sets an integer variable to a given value as an atomic operation.

Syntax

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

Parameters

Target

A pointer to a variable to be set to the supplied Value as an atomic operation.

Value

Specifies the value to which the variable will be set.

Return Value

InterlockedExchange returns the value of the variable at Target when the call occurred.

Remarks

InterlockedExchange should be used instead of ExInterlockedExchangeUlong, because it is both faster and more efficient.

InterlockedExchange is implemented inline by the compiler when appropriate and possible. It does not require a spin lock and can therefore be safely used on pageable data.

A call to InterlockedExchange routine is atomic only with respect to other InterlockedXxx calls.

Interlocked operations cannot be used on non-cached memory.

Requirements

   
Minimum supported client Available starting with Windows 2000.
Target Platform Universal
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h, Miniport.h)
Library OneCoreUAP.lib on Windows 10
IRQL Any level

See Also

ExInterlockedAddLargeInteger

ExInterlockedAddUlong

InterlockedDecrement

InterlockedIncrement