|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C includes built-in support for threads, atomic operations, mutual exclusion, condition variables, and thread-specific storages.
These features are optionally provided:
__STDC_NO_THREADS__ is defined by the compiler, the header<threads.h> and all of the names provided in it are not provided;__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 |
Defined in header <threads.h> | |
thrd_t | implementation-defined complete object type identifying a thread[edit] |
(C11) | creates a thread (function)[edit] |
(C11) | checks if two identifiers refer to the same thread (function)[edit] |
(C11) | obtains the current thread identifier (function)[edit] |
(C11) | suspends execution of the calling thread for the given period of time (function)[edit] |
(C11) | yields the current time slice (function)[edit] |
(C11) | terminates the calling thread (function)[edit] |
(C11) | detaches a thread (function)[edit] |
(C11) | blocks until a thread terminates (function)[edit] |
| indicates a thread error status (constant)[edit] | |
thrd_start_t (C11) | a typedef of the function pointer typeint(*)(void*), used bythrd_create (typedef)[edit] |
Defined in header <stdatomic.h> | |
Operations on atomic types | |
| indicates that the given atomic type is lock-free (macro constant)[edit] | |
(C11) | indicates whether the atomic object is lock-free (function)[edit] |
| stores a value in an atomic object (function)[edit] | |
| reads a value from an atomic object (function)[edit] | |
| swaps a value with the value of an atomic object (function)[edit] | |
| swaps a value with an atomic object if the old value is what is expected, otherwise reads the old value (function)[edit] | |
| atomic addition (function)[edit] | |
| atomic subtraction (function)[edit] | |
| atomic bitwise OR (function)[edit] | |
| atomic bitwise exclusive OR (function)[edit] | |
| atomic bitwise AND (function)[edit] | |
Flag type and operations | |
(C11) | lock-free atomic boolean flag (struct)[edit] |
| sets an atomic_flag to true and returns the old value (function)[edit] | |
| sets an atomic_flag to false (function)[edit] | |
Initialization | |
(C11) | initializes an existing atomic object (function)[edit] |
(C11)(deprecated in C17)(removed in C23) | initializes a new atomic object (function macro)[edit] |
(C11) | initializes a newatomic_flag (macro constant)[edit] |
Memory synchronization ordering | |
(C11) | defines memory ordering constraints (enum)[edit] |
(C11) | breaks a dependency chain formemory_order_consume (function macro)[edit] |
(C11) | generic memory order-dependent fence synchronization primitive (function)[edit] |
(C11) | fence between a thread and a signal handler executed in the same thread (function)[edit] |
Convenience type aliases | |
| Typedef name | Full type name |
atomic_bool(C11) | _Atomic _Bool(until C23)_Atomic bool(since C23) |
atomic_char(C11) | _Atomicchar |
atomic_schar(C11) | _Atomicsignedchar |
atomic_uchar(C11) | _Atomicunsignedchar |
atomic_short(C11) | _Atomicshort |
atomic_ushort(C11) | _Atomicunsignedshort |
atomic_int(C11) | _Atomicint |
atomic_uint(C11) | _Atomicunsignedint |
atomic_long(C11) | _Atomiclong |
atomic_ulong(C11) | _Atomicunsignedlong |
atomic_llong(C11) | _Atomiclonglong |
atomic_ullong(C11) | _Atomicunsignedlonglong |
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) | _Atomicwchar_t |
atomic_int_least8_t(C11) | _Atomicint_least8_t |
atomic_uint_least8_t(C11) | _Atomicuint_least8_t |
atomic_int_least16_t(C11) | _Atomicint_least16_t |
atomic_uint_least16_t(C11) | _Atomicuint_least16_t |
atomic_int_least32_t(C11) | _Atomicint_least32_t |
atomic_uint_least32_t(C11) | _Atomicuint_least32_t |
atomic_int_least64_t(C11) | _Atomicint_least64_t |
atomic_uint_least64_t(C11) | _Atomicuint_least64_t |
atomic_int_fast8_t(C11) | _Atomicint_fast8_t |
atomic_uint_fast8_t(C11) | _Atomicuint_fast8_t |
atomic_int_fast16_t(C11) | _Atomicint_fast16_t |
atomic_uint_fast16_t(C11) | _Atomicuint_fast16_t |
atomic_int_fast32_t(C11) | _Atomicint_fast32_t |
atomic_uint_fast32_t(C11) | _Atomicuint_fast32_t |
atomic_int_fast64_t(C11) | _Atomicint_fast64_t |
atomic_uint_fast64_t(C11) | _Atomicuint_fast64_t |
atomic_intptr_t(C11) | _Atomicintptr_t |
atomic_uintptr_t(C11) | _Atomicuintptr_t |
atomic_size_t(C11) | _Atomicsize_t |
atomic_ptrdiff_t(C11) | _Atomicptrdiff_t |
atomic_intmax_t(C11) | _Atomicintmax_t |
atomic_uintmax_t(C11) | _Atomicuintmax_t |
Defined in header <threads.h> | |
mtx_t | mutex identifier[edit] |
(C11) | creates a mutex (function)[edit] |
(C11) | blocks until locks a mutex (function)[edit] |
(C11) | blocks until locks a mutex or times out (function)[edit] |
(C11) | locks a mutex or returns without blocking if already locked (function)[edit] |
(C11) | unlocks a mutex (function)[edit] |
(C11) | destroys a mutex (function)[edit] |
(C11)(C11)(C11) | defines the type of a mutex (enum)[edit] |
Call once | |
(C11) | calls a function exactly once (function)[edit] |
Defined in header <threads.h> | |
cnd_t | condition variable identifier |
(C11) | creates a condition variable (function)[edit] |
(C11) | unblocks one thread blocked on a condition variable (function)[edit] |
(C11) | unblocks all threads blocked on a condition variable (function)[edit] |
(C11) | blocks on a condition variable (function)[edit] |
(C11) | blocks on a condition variable, with a timeout (function)[edit] |
(C11) | destroys a condition variable (function)[edit] |
Defined in header <threads.h> | |
(C11)(removed in C23) | convenience macro for storage-class specifier_Thread_local (keyword macro)[edit] |
tss_t | thread-specific storage pointer[edit] |
(C11) | maximum number of times destructors are called (macro constant)[edit] |
tss_dtor_t(C11) | function pointer typevoid(*)(void*), used for TSS destructor (typedef)[edit] |
(C11) | creates thread-specific storage pointer with a given destructor (function)[edit] |
(C11) | reads from thread-specific storage (function)[edit] |
(C11) | write to thread-specific storage (function)[edit] |
(C11) | releases the resources held by a given thread-specific pointer (function)[edit] |
In future revisions of the C standard:
cnd_,mtx_,thrd_, ortss_, and a lowercase letter may be added to the declarations in the<threads.h> header;ATOMIC_ and an uppercase letter may be added to the macros defined in the<stdatomic.h> header;atomic_ ormemory_, and a lowercase letter may be added to the declarations in the<stdatomic.h> header;memory_order_ and a lowercase letter may be added to the definition of thememory_order type in the<stdatomic.h> header;atomic_ and a lowercase letter may be added to the declarations in the<stdatomic.h> header.Identifiers reserved for functions names are alwayspotentially(since C23) reserved for use as identifiers with external linkage, while other identifiers list here arepotentially(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.
C++ documentation forConcurrency support library |
| GNU GCC Libc Manual: ISO C Mutexes |