InterlockedCompareExchange (Windows CE 5.0)

Send Feedback

This function performs an atomic comparison of the specified values and exchanges the values based on the outcome of the comparison. The function prevents more than one thread from using the same variable simultaneously.

LONG InterlockedCompareExchange(LPLONG Destination, LONG Exchange, LONG Comperand);

Parameters

  • Destination
    [in, out] Specifies the address of the destination value. The sign is ignored.
  • Exchange
    [in] Specifies the exchange value. The sign is ignored.
  • Comperand
    [in] Specifies the value to compare to Destination. The sign is ignored.

Return Values

The return value is the initial value of the destination.

Remarks

The InterlockedCompareExchange, InterlockedDecrement, InterlockedExchange, InterlockedExchangeAdd, and InterlockedIncrement 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 InterlockedCompareExchange function performs an atomic comparison of the Destination value with the Comperand value. If the Destination value is equal to the Comperand value, the Exchange value is stored in the address specified by Destination. Otherwise, no operation is performed.

The variables for InterlockedCompareExchange must be aligned on a 32-bit boundary.

Each object type, such as memory maps, semaphores, events, message queues, mutexes, and watchdog timers, has its own separate namespace. Empty strings, "", are handled as named objects. On Windows desktop-based platforms, synchronization objects all share the same namespace.

Requirements

OS Versions: Windows CE .NET 4.0 and later.
Header: Windows.h.
Link Library: Coredll.lib.

See Also

InterlockedExchange | InterlockedDecrement | InterlockedIncrement | InterlockedExchangeAdd

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.