Concurrency support library
From cppreference.com
 
 
 < c 
 
 
  C 
 Concurrency support (C11)
 Concurrency support library
 
  
 
 
  
 Threads
 Atomic operations
(until C23)
 Atomic flags
 Memory ordering
 Mutual exclusion
 Condition variables
 Thread-local storage
C includes built-in support for threads, atomic operations, mutual exclusion, condition variables, and thread-specific storages.
These features are optionally provided:
-  if the macro constant __STDC_NO_THREADS__is defined by the compiler, the header <threads.h> and all of the names provided in it are not provided;
-  if the macro constant __STDC_NO_ATOMICS__is defined by the compiler, the header <stdatomic.h> and all of the names provided in it are not provided.
See also _Atomic type specifier and qualifier.
Contents
[edit] Threads
Defined in header 
<threads.h>  thrd_t
 implementation-defined complete object type identifying a thread [edit] 
thrd_start_t
(C11)
(typedef) [edit]
[edit] Atomic operations
Defined in header 
<stdatomic.h>  Operations on atomic types
 
 swaps a value with an atomic object if the old value is what is expected, otherwise reads the old value 
(function) [edit]
(function) [edit]
Flag type and operations
Initialization
Memory synchronization ordering
Convenience type aliases
 Typedef name
 Full type name
atomic_bool (C11)
 _Atomic _Bool(until C23)_Atomic bool(since C23)
atomic_char (C11)
 _Atomic char
atomic_schar (C11)
 _Atomic signed char
atomic_uchar (C11)
 _Atomic unsigned char
atomic_short (C11)
 _Atomic short
atomic_ushort (C11)
 _Atomic unsigned short
atomic_int (C11)
 _Atomic int
atomic_uint (C11)
 _Atomic unsigned int
atomic_long (C11)
 _Atomic long
atomic_ulong (C11)
 _Atomic unsigned long
atomic_llong (C11)
 _Atomic long long
atomic_ullong (C11)
 _Atomic unsigned long long
atomic_char8_t (C23)
 _Atomic char8_t
atomic_char16_t (C11)
 _Atomic char16_t
atomic_char32_t (C11)
 _Atomic char32_t
atomic_wchar_t (C11)
 _Atomic wchar_t
[edit] Mutual exclusion
Defined in header 
<threads.h>  mtx_t
 mutex identifier [edit] 
Call once
[edit] Condition variables
Defined in header 
<threads.h>  cnd_t
 condition variable identifier
[edit] Thread-local storage
Defined in header 
<threads.h>  (C11)(removed in C23)
(keyword macro) [edit]
tss_t
 thread-specific storage pointer [edit] 
[edit] Reserved identifiers
In future revisions of the C standard:
-  function names, type names, and enumeration constants that begin with either cnd_,mtx_,thrd_, ortss_, and a lowercase letter may be added to the declarations in the<threads.h>header;
-  macros that begin with ATOMIC_and an uppercase letter may be added to the macros defined in the <stdatomic.h> header;
-  typedef names that begin with either atomic_ormemory_, and a lowercase letter may be added to the declarations in the <stdatomic.h> header;
-  enumeration constants that begin with memory_order_and a lowercase letter may be added to the definition of the memory_order type in the <stdatomic.h> header;
-  function names that begin with atomic_and a lowercase letter may be added to the declarations in the <stdatomic.h> header.
Identifiers reserved for functions names are always potentially(since C23) reserved for use as identifiers with external linkage, while other identifiers list here are potentially(since C23) reserved when <stdatomic.h> is included.
Declaring, defining, or #undefing such an identifier results in undefined behavior if it is provided by the standard or implementation(since C23). Portable programs should not use those identifiers.
[edit] References
- C23 standard (ISO/IEC 9899:2024):
- 7.17 Atomics <stdatomic.h> (p: TBD)
 
- 7.26 Threads <threads.h> (p: TBD)
 
- 7.31.8 Atomics <stdatomic.h> (p: TBD)
 
- 7.31.15 Threads <threads.h> (p: TBD)
 
- C17 standard (ISO/IEC 9899:2018):
- 7.17 Atomics <stdatomic.h> (p: 200-209)
 
- 7.26 Threads <threads.h> (p: 274-283)
 
- 7.31.8 Atomics <stdatomic.h> (p: 332)
 
- 7.31.15 Threads <threads.h> (p: 333)
 
- C11 standard (ISO/IEC 9899:2011):
- 7.17 Atomics <stdatomic.h> (p: 273-286)
 
- 7.26 Threads <threads.h> (p: 376-387)
 
- 7.31.8 Atomics <stdatomic.h> (p: 455-456)
 
- 7.31.15 Threads <threads.h> (p: 456)
 
[edit] See also
C++ documentation  for Concurrency support library