Share via


Fonction InterlockedExchange (winnt.h)

Définit une variable 32 bits sur la valeur spécifiée en tant qu’opération atomique.

Pour fonctionner sur une variable de pointeur, utilisez la fonction InterlockedExchangePointer .

Pour fonctionner sur une variable 16 bits, utilisez la fonction InterlockedExchange16 .

Pour fonctionner sur une variable 64 bits, utilisez la fonction InterlockedExchange64 .

Syntaxe

LONG InterlockedExchange(
  [in, out] LONG volatile *Target,
  [in]      LONG          Value
);

Paramètres

[in, out] Target

Pointeur vers la valeur à échanger. La fonction définit cette variable sur Value et retourne sa valeur précédente.

[in] Value

Valeur à échanger avec la valeur pointée par Target.

Valeur retournée

La fonction retourne la valeur initiale du paramètre Target .

Remarques

Les fonctions verrouillées fournissent un mécanisme simple pour synchroniser l’accès à une variable partagée par plusieurs threads. Cette fonction est atomique par rapport aux appels à d’autres fonctions verrouillées.

Cette fonction est implémentée à l’aide d’une intrinsèque du compilateur dans la mesure du possible. Pour plus d’informations, consultez le fichier d’en-tête WinBase.h et _InterlockedExchange.

Cette fonction génère une barrière de mémoire complète (ou clôture) pour s’assurer que les opérations de mémoire sont effectuées dans l’ordre.

Systèmes itanium : Pour les applications critiques en matière de performances, utilisez plutôt InterlockedExchangeAcquire .

Note Cette fonction est prise en charge sur les systèmes basés sur Windows RT.
 

Configuration requise

Condition requise Valeur
Client minimal pris en charge Windows XP [applications de bureau | applications UWP]
Serveur minimal pris en charge Windows Server 2003 [applications de bureau | applications UWP]
Plateforme cible Windows
En-tête winnt.h (inclure Windows.h)
Bibliothèque Kernel32.lib
DLL Kernel32.dll

Voir aussi

Accès variable verrouillé

InterlockedCompareExchange

InterlockedExchange

InterlockedExchange16

InterlockedExchange16Acquire

InterlockedExchange16NoFence

InterlockedExchange64

InterlockedExchange8

InterlockedExchangeAcquire

InterlockedExchangeAcquire64

InterlockedExchangeAdd

InterlockedExchangeAdd64

InterlockedExchangeAddAcquire

InterlockedExchangeAddAcquire64

InterlockedExchangeAddNoFence

InterlockedExchangeAddNoFence64

InterlockedExchangeAddRelease

InterlockedExchangeAddRelease64

InterlockedExchangeNoFence

InterlockedExchangeNoFence64

InterlockedExchangePointer

InterlockedExchangePointerAcquire

InterlockedExchangePointerNoFence

InterlockedExchangeSubtract

Fonctions de synchronisation