interlockedCompareExchange16 函式 (winnt.h)

在指定的值上執行不可部分完成的比較和交換作業。 函式會根據比較的結果,比較兩個指定的16位值,並與另一個16位值交換。

若要在 32 位值上運作,請使用 InterlockedCompareExchange 函式。

若要在 64 位值上運作,請使用 InterlockedCompareExchange64 函式。

若要在128位值上運作,請使用 InterlockedCompareExchange128 函式。

語法

SHORT InterlockedCompareExchange16(
  [in, out] SHORT volatile *Destination,
  [in]      SHORT          ExChange,
  [in]      SHORT          Comperand
);

參數

[in, out] Destination

目的地值的指標。

[in] ExChange

交換值。

[in] Comperand

要與 Destination 比較的值。

傳回值

函式會傳回 Destination 參數的初始值。

備註

函式會比較 Destination 值與 Compareand 值。 如果 Destination 值等於 Comparand 值, Exchange 值會儲存在 Destination 所指定的位址中。 否則,不會執行任何作業。

此函式的參數必須在16位界限上對齊;否則,函式會在多處理器 x86 系統和任何非 x86 系統上發生無法預期的行為。 請參閱 _aligned_malloc

連結函式提供簡單的機制,可同步存取多個線程所共享的變數。 此函式對其他連結函式的呼叫是不可部分完成的。

此函式會盡可能使用編譯程式內部函數來實作。 如需詳細資訊,請參閱 WinBase.h 頭文件及 _InterlockedCompareExchange16

此函式會產生完整的記憶體屏障 (或柵欄) ,以確保記憶體作業會依序完成。

注意Windows RT 型系統支援此函式。
 

規格需求

需求
最低支援的用戶端 Windows 8 [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2012 [僅限傳統型應用程式]
目標平台 Windows
標頭 winnt.h (包含 Windows.h)

另請參閱

Interlocked Variable Access

InterlockedCompare64Exchange128

InterlockedCompareExchange

InterlockedCompareExchange128

InterlockedCompareExchange16Acquire

InterlockedCompareExchange16NoFence

InterlockedCompareExchange16Release

InterlockedCompareExchange64

InterlockedCompareExchangeAcquire

InterlockedCompareExchangeAcquire64

InterlockedCompareExchangeNoFence

InterlockedCompareExchangeNoFence64

InterlockedCompareExchangePointer

InterlockedCompareExchangePointerAcquire

InterlockedCompareExchangePointerNoFence

InterlockedCompareExchangePointerRelease

InterlockedCompareExchangeRelease

InterlockedCompareExchangeRelease64

同步處理函式