Difference between revisions of "cpp/thread"
(simplify wording) |
(spelling, wording, links) |
||
Line 6: | Line 6: | ||
===Threads=== | ===Threads=== | ||
− | Threads enable | + | Threads enable programs to execute across several processor cores. |
{{dcl list begin}} | {{dcl list begin}} | ||
Line 50: | Line 50: | ||
{{dcl list begin}} | {{dcl list begin}} | ||
− | {{dcl list class | cpp/thread/condition_variable | provides a condition variable | + | {{dcl list class | cpp/thread/condition_variable | provides a condition variable associated with a {{c|std::unique_lock}} | notes={{mark c++11}}}} |
{{dcl list class | cpp/thread/condition_variable_any | provides a condition variable associated with any lock type | notes={{mark c++11}}}} | {{dcl list class | cpp/thread/condition_variable_any | provides a condition variable associated with any lock type | notes={{mark c++11}}}} | ||
− | {{dcl list fun | cpp/thread/notify_all_at_thread_exit | schedules a call to notify_all to be invoked when this thread exits | notes={{mark c++11}}}} | + | {{dcl list fun | cpp/thread/notify_all_at_thread_exit | schedules a call to {{tt|notify_all}} to be invoked when this thread exits | notes={{mark c++11}}}} |
{{dcl list enum | cpp/thread/cv_status | lists the possible results of timed waits on condition variables | notes={{mark c++11}}}} | {{dcl list enum | cpp/thread/cv_status | lists the possible results of timed waits on condition variables | notes={{mark c++11}}}} | ||
{{dcl list end}} | {{dcl list end}} |
Revision as of 06:45, 17 July 2012
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 eachother. 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.
(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 exits (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.