A version of this page is also available for
This function atomically exchanges a pair of values. The function prevents more than one thread from using the same variable simultaneously.
If you are exchanging pointer values, this function supersedes
[in, out] Pointer to the pointer to the value to exchange. The function sets the value to
[in] New value for
Initial value pointed to by
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.
Header winbase.h Library coredll.lib Windows Embedded CE Windows CE .NET 4.0 and later Windows Mobile Windows Mobile Version 5.0 and later