Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function is an interlocked function that performs a conditional setting of a variable.

Syntax

LONG WINAPI InterlockedTestExchange(
  LPLONG 
Target,
  LONG 
OldValue,
  LONG 
NewValue
);

Parameters

Target

[in] Pointer to the LONGvariable to check and set.

OldValue

[in] Value to check against.

NewValue

[in] Value to set to conditionally.

Return Value

The original value pointed to by Targetat the time of the call indicates success.

Remarks

The InterlockedTestExchangefunction is an interlocked function. In other words, it can be considered atomic. It checks to see if the value pointed to by Targetis equal to OldValue. If so, it sets Targetto NewValue. Because InterlockedTestExchangereturns the old value pointed to by Target, if the return value is OldValue, then InterlockedTestExchangesucceeded and set the value pointed to by Targetto NewValue. Otherwise, it failed.

Requirements

Header winbase.h
Library coredll.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also