[ Web Proxy ]
URL:
Viewing: https://ko.cppreference.com/cpp/thread [Back]  [Original]

Thread support library - cppreference.com
cppreference.com

Thread support library

cppreference.com
< cpp
 
 
Thread support library
Threads
(C++11)
this_thread namespace
(C++11)
(C++11)
(C++11)
Mutual exclusion
(C++11)
Generic lock management
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Condition variables
(C++11)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
 

C++ , , , futures .

.


:cpp/thread/dsc jthread
<thread> .
(C++11)
manages a separate thread
(class) [edit]
Functions managing the current thread
Defined in namespace this_thread
(C++11)
suggests that the implementation reschedule execution of threads
(function) [edit]
(C++11)
returns the thread id of the current thread
(function) [edit]
(C++11)
stops the execution of the current thread for a specified time duration
(function) [edit]
stops the execution of the current thread until a specified time point
(function) [edit]

The stop_XXX types are designed to enable thread cancellation for std::jthread, although they can also be used independently of std::jthread - for example to interrupt std::condition_variable_any waiting functions, or for a custom thread management implementation. In fact they do not even need to be used to "stop" anything, but can instead be used for a thread-safe one-time function(s) invocation trigger, for example.

:cpp/thread/dsc stop token:cpp/thread/dsc stop source:cpp/thread/dsc stop callback
<stop_token> .
(since C++20)

:cpp/thread/dsc hardware destructive interference size
<new> .

. , .

:cpp/thread/dsc shared timed mutex
<mutex> .
(C++11)
provides basic mutual exclusion facility
(class) [edit]
provides mutual exclusion facility which implements locking with a timeout
(class) [edit]
provides mutual exclusion facility which can be locked recursively by the same thread
(class) [edit]
provides mutual exclusion facility which can be locked recursively
by the same thread and implements locking with a timeout
(class) [edit]
<shared_mutex> .
provides shared mutual exclusion facility
(class) [edit]
Generic mutex management
<mutex> .
implements a strictly scope-based mutex ownership wrapper
(class template) [edit]
deadlock-avoiding RAII wrapper for multiple mutexes
(class template) [edit]
implements movable mutex ownership wrapper
(class template) [edit]
implements movable shared mutex ownership wrapper
(class template) [edit]
tag type used to specify locking strategy
(class) [edit]
tag constants used to specify locking strategy
(constant) [edit]
Generic locking algorithms
(C++11)
attempts to obtain ownership of mutexes via repeated calls to try_lock
(function template) [edit]
(C++11)
locks specified mutexes, blocks if any are unavailable
(function template) [edit]
Call once
(C++11)
helper object to ensure that call_once invokes the function only once
(class) [edit]
(C++11)
invokes a function only once even if called from multiple threads
(function template) [edit]

(condition variable) . ( .) .

:cpp/thread/dsc notify all at thread exit:cpp/thread/dsc cv status
<condition_variable> .
provides a condition variable associated with a std::unique_lock
(class) [edit]
provides a condition variable associated with any lock type
(class) [edit]

Semaphores

A semaphore is a lightweight synchronization primitive used to constrain concurrent access to a shared resource. When it's possible to use both, semaphore can be more efficient than condition variable.

:cpp/thread/dsc counting semaphore:cpp/thread/dsc binary semaphore
<semaphore> .

Latches and Barriers

Latches and barriers are thread coordination mechanism that allows any number of threads to block until an expected number of threads arrive at the barrier. Latches cannot be reused, barriers can be used repeatedly.

:cpp/thread/dsc latch:cpp/thread/dsc barrier
<latch> .
<barrier> .


(since C++20)

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.

<future> .
(C++11)
stores a value for asynchronous retrieval
(class template) [edit]
packages a function to store its return value for asynchronous retrieval
(class template) [edit]
(C++11)
waits for a value that is set asynchronously
(class template) [edit]
waits for a value (possibly referenced by other futures) that is set asynchronously
(class template) [edit]
(C++11)
runs a function asynchronously (potentially in a new thread) and returns a std::future that will hold the result
(function template) [edit]
(C++11)
specifies the launch policy for std::async
(enum) [edit]
specifies the results of timed waits performed on std::future and std::shared_future
(enum) [edit]
Future errors
reports an error related to futures or promises
(class) [edit]
identifies the future error category
(function) [edit]
identifies the future error codes
(enum) [edit]

See also

C documentation for Thread support library

Web Proxy Viewer  |  New URL  |  Original Page