Compartilhar via


Função InterlockedCompareExchangeToUser (usermode_accessors.h)

The InterlockedCompareExchangeToUser function performs an atomic compare-and-exchange operation on a 32-bit value in user-mode memory.

Syntax

LONG InterlockedCompareExchangeToUser(
  LONG volatile *Destination,
  LONG          ExChange,
  LONG          Comperand
);

Parameters

Destination

[dentro, fora] Um ponteiro para o local de memória do modo de usuário que contém o valor de destino. The pointer must be naturally aligned for the data type; that is, the memory location must be 4-byte aligned since Destination points to a 4-byte type.

ExChange

[in] O valor de troca.

Comperand

[in] The value to compare to Destination.

Return value

The function returns the initial value of the Destination parameter.

Remarks

As funções intertravadas fornecem um mecanismo simples para sincronizar o acesso a uma variável compartilhada por vários threads. Essa função é atômica em relação a chamadas para outras funções intertravadas. Ele gera uma barreira de memória completa para garantir que as operações de memória sejam concluídas em ordem.

Essa função fornece acesso atômico de comparação e troca a um valor de 32 bits na memória do modo de usuário. The function compares 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. Caso contrário, nenhuma operação será executada.

A função gerará uma exceção estruturada se a operação falhar, como quando o endereço de destino não for um endereço válido no modo de usuário ou estiver inacessível.

Essa função funciona em todas as versões do Windows, não apenas nas mais recentes. You need to consume the latest WDK to get the function declaration from the usermode_accessors.h header. You also need the library (umaccess.lib) from the latest WDK. No entanto, o driver resultante será executado bem em versões mais antigas do Windows.

Requirements

Requirement Value
Cliente mínimo suportado See Remarks
Header usermode_accessors.h
Library umaccess.lib
IRQL Menor ou igual a APC_LEVEL

See also

InterlockedCompareExchangeToMode

InterlockedCompareExchange64ToUser