interlockedCompareExchange128 函式 (winnt.h)

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

若要在16位值上運作,請使用 InterlockedCompareExchange16 函式。

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

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

語法

BOOLEAN InterlockedCompareExchange128(
  [in, out] LONG64 volatile *Destination,
  [in]      LONG64          ExchangeHigh,
  [in]      LONG64          ExchangeLow,
  [in, out] LONG64          *ComparandResult
);

參數

[in, out] Destination

目的地值的指標。 此參數是兩個64位整數的陣列,被視為128位字段。

[in] ExchangeHigh

交換值的最高部分。

[in] ExchangeLow

交換值的低部分。

[in, out] ComparandResult

要比較的值。 此參數是兩個64位整數的陣列,被視為128位字段。 在輸出上,這會以目的地的原始值覆寫。

傳回值

如果 ComparandResult 等於 Destination 參數的原始值,則函式會傳回 1;如果 ComparandResult 不等於 Destination 參數的原始值,則為 0。

備註

函式會比較 Destination 值與 CompareandResult 值:

  • 如果 Destination 值等於 ComparandResult 值, ExchangeHighExchangeLow 值會儲存在 Destination 所指定的陣列中,也會儲存在 ComparandResult 所指定的陣列中。
  • 否則, 目的地 會保持未修改。
不論比較的結果為何,原始 的 Destination 值都會儲存在 ComparandResult 所指定的陣列中。

此函式的參數必須對齊 16 位元組界限;否則,函式會在 x64 系統上無法預期運作。 請參閱 _aligned_malloc

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

此函式僅適用於 x64 型系統,並且會使用編譯程式內部函數來實作。 如需詳細資訊,請參閱 WinBase.h 頭檔與 _InterlockedCompareExchange128

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

規格需求

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

另請參閱

相互鎖定的變數存取

InterlockedCompare64Exchange128

InterlockedCompareExchange

InterlockedCompareExchange16

InterlockedCompareExchange16Acquire

InterlockedCompareExchange16NoFence

InterlockedCompareExchange16Release

InterlockedCompareExchange64

InterlockedCompareExchangeAcquire

InterlockedCompareExchangeAcquire64

InterlockedCompareExchangeNoFence

InterlockedCompareExchangeNoFence64

InterlockedCompareExchangePointer

InterlockedCompareExchangePointerAcquire

InterlockedCompareExchangePointerNoFence

InterlockedCompareExchangePointerRelease

InterlockedCompareExchangeRelease

InterlockedCompareExchangeRelease64

同步處理函式