Thread support library
C++ includes built-in support for threads, mutual exclusion, condition variables, and futures.
Contents |
Threads
Threads enable programs to execute across several processor cores.
Defined in header
<thread> | |
Functions managing the current thread | |
Defined in namespace
this_thread |
Mutual exclusion
Mutual exclusion algorithms prevent multiple threads from simultaneously accessing shared resources. This prevents data races and provides support for synchronization between threads.
Condition variables
A condition variable is a synchronization primitive that allows multiple threads to communicate with each other. It allows some number of threads to wait (possibly with a timeout) for notification from another thread that they may proceed. A condition variable is always associated with a mutex.
Defined in header
<condition_variable> | |
(C++11) |
provides a condition variable associated with a std::unique_lock (class) |
(C++11) |
provides a condition variable associated with any lock type (class) |
(C++11) |
schedules a call to notify_all to be invoked when this thread is completely finished (function) |
(C++11) |
lists the possible results of timed waits on condition variables (enum) |
Futures
The standard library provides facilities to obtain values that are returned and to catch exceptions that are thrown by asynchronous tasks (i.e. functions launched in separate threads). These values are communicated in a shared state, in which the asynchronous task may write its return value or store an exception, and which may be examined, waited for, and otherwise manipulated by other threads that hold instances of std::future or std::shared_future that reference that shared state.