Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/thread"

From cppreference.com
< cpp
m (r2.7.3) (Robot: Adding ar, de, es, fr, it, ja, pt, ru, zh)
m
Line 47: Line 47:
 
===Condition variables===
 
===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.  
+
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.  
  
 
{{dcl list begin}}
 
{{dcl list begin}}

Revision as of 11:54, 5 January 2013

 
 
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
Safe Reclamation
(C++26)
Hazard Pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
Memory ordering
Free functions for atomic operations
Free functions for atomic flags
 

C++ includes built-in support for threads, mutual exclusion, condition variables, and futures.

Contents

Threads

Threads enable programs to execute across several processor cores.

Template:cpp/thread/dcl list threadTemplate:cpp/thread/dcl list yieldTemplate:cpp/thread/dcl list get idTemplate:cpp/thread/dcl list sleep forTemplate:cpp/thread/dcl list sleep until
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.

Template:cpp/thread/dcl list mutexTemplate:cpp/thread/dcl list timed mutexTemplate:cpp/thread/dcl list recursive mutexTemplate:cpp/thread/dcl list recursive timed mutexTemplate:cpp/thread/dcl list lock guardTemplate:cpp/thread/dcl list unique lockTemplate:cpp/thread/dcl list lock tag tTemplate:cpp/thread/dcl list lock tagTemplate:cpp/thread/dcl list try lockTemplate:cpp/thread/dcl list lockTemplate:cpp/thread/dcl list once flagTemplate:cpp/thread/dcl list call once
Defined in header <mutex>
Generic mutex management
Generic locking algorithms
Call once

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>
provides a condition variable associated with a std::unique_lock
(class)
provides a condition variable associated with any lock type
(class)
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.

Template:cpp/thread/dcl list promiseTemplate:cpp/thread/dcl list packaged taskTemplate:cpp/thread/dcl list futureTemplate:cpp/thread/dcl list shared futureTemplate:cpp/thread/dcl list asyncTemplate:cpp/thread/dcl list launchTemplate:cpp/thread/dcl list future statusTemplate:cpp/thread/dcl list future errorTemplate:cpp/thread/dcl list future categoryTemplate:cpp/thread/dcl list future errc
Defined in header <future>
Future errors