interlockedCompareExchangePointer 函式 (winnt.h)

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

若要在非指標值上操作,請使用 InterlockedCompareExchange 函式。

語法

PVOID InterlockedCompareExchangePointer(
  [in, out] PVOID volatile *Destination,
  [in]      PVOID          Exchange,
  [in]      PVOID          Comperand
);

參數

[in, out] Destination

目的地值的指標。

[in] Exchange

交換值。

[in] Comperand

要與 Destination 比較的值。

傳回值

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

備註

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

在64位系統上,參數為64位,且必須在64位界限上對齊;否則,函式的行為會無法預期。 在 32 位元系統上,參數為 32 位元,而且必須在 32 位元界限上對齊。

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

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

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

Itanium 型系統: 針對效能關鍵性應用程式,請改用 InterlockedCompareExchangePointerAcquireInterlockedCompareExchangePointerRelease

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

規格需求

需求
最低支援的用戶端 Windows XP [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2003 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 winnt.h (包括 Windows.h)

另請參閱

相互鎖定的變數存取

InterlockedCompare64Exchange128

InterlockedCompareExchange

InterlockedCompareExchange128

InterlockedCompareExchange16

InterlockedCompareExchange16Acquire

InterlockedCompareExchange16NoFence

InterlockedCompareExchange16Release

InterlockedCompareExchange64

InterlockedCompareExchangeAcquire

InterlockedCompareExchangeAcquire64

InterlockedCompareExchangeNoFence

InterlockedCompareExchangeNoFence64

InterlockedCompareExchangePointerAcquire

InterlockedCompareExchangePointerNoFence

InterlockedCompareExchangePointerRelease

InterlockedCompareExchangeRelease

InterlockedCompareExchangeRelease64

同步處理函式