#include <stdatomic.h>
L'entête <stdatomic.h> fournit des alias de types atomiques pour les principaux types entiers.
Ces alias évitent d'écrire directement _Atomic devant chaque type.
| Nom | Type direct | Depuis |
|---|---|---|
atomic_bool |
_Atomic _Bool |
C11 |
atomic_char |
_Atomic char |
C11 |
atomic_schar |
_Atomic signed char |
C11 |
atomic_uchar |
_Atomic unsigned char |
C11 |
atomic_short |
_Atomic short |
C11 |
atomic_ushort |
_Atomic unsigned short |
C11 |
atomic_int |
_Atomic int |
C11 |
atomic_uint |
_Atomic unsigned int |
C11 |
atomic_long |
_Atomic long |
C11 |
atomic_ulong |
_Atomic unsigned long |
C11 |
atomic_llong |
_Atomic long long |
C11 |
atomic_ullong |
_Atomic unsigned long long |
C11 |
atomic_char8_t |
_Atomic char8_t |
C23 |
atomic_char16_t |
_Atomic char16_t |
C11 |
atomic_char32_t |
_Atomic char32_t |
C11 |
atomic_wchar_t |
_Atomic wchar_t |
C11 |
atomic_int_least8_t |
_Atomic int_least8_t |
C11 |
atomic_uint_least8_t |
_Atomic uint_least8_t |
C11 |
atomic_int_least16_t |
_Atomic int_least16_t |
C11 |
atomic_uint_least16_t |
_Atomic uint_least16_t |
C11 |
atomic_int_least32_t |
_Atomic int_least32_t |
C11 |
atomic_uint_least32_t |
_Atomic uint_least32_t |
C11 |
atomic_int_least64_t |
_Atomic int_least64_t |
C11 |
atomic_uint_least64_t |
_Atomic uint_least64_t |
C11 |
atomic_int_fast8_t |
_Atomic int_fast8_t |
C11 |
atomic_uint_fast8_t |
_Atomic uint_fast8_t |
C11 |
atomic_int_fast16_t |
_Atomic int_fast16_t |
C11 |
atomic_uint_fast16_t |
_Atomic uint_fast16_t |
C11 |
atomic_int_fast32_t |
_Atomic int_fast32_t |
C11 |
atomic_uint_fast32_t |
_Atomic uint_fast32_t |
C11 |
atomic_int_fast64_t |
_Atomic int_fast64_t |
C11 |
atomic_uint_fast64_t |
_Atomic uint_fast64_t |
C11 |
atomic_intptr_t |
_Atomic intptr_t |
C11 |
atomic_uintptr_t |
_Atomic uintptr_t |
C11 |
atomic_size_t |
_Atomic size_t |
C11 |
atomic_ptrdiff_t |
_Atomic ptrdiff_t |
C11 |
atomic_intmax_t |
_Atomic intmax_t |
C11 |
atomic_uintmax_t |
_Atomic uintmax_t |
C11 |
L'exemple suivant utilise un compteur atomique de type atomic_uint.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <stdatomic.h> #include <stdio.h> #include <stdlib.h> int main() { atomic_uint counter = 0; atomic_fetch_add( &counter, 1 ); atomic_fetch_add( &counter, 1 ); printf( "%u\n", atomic_load( &counter ) ); return EXIT_SUCCESS; } |
Cet exemple produit l'affichage suivant.
2
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :