Thread support library
C++은 쓰레드, 상호 배제, 조건변수, futures를 지원한다.
목차 |
[편집] 쓰레드
쓰레드를 이용하면 프로그램은 여러 프로세서 코어에서 작업을 수행할 수 있다.
<thread> 헤더에 정의됨. | |
(C++11) |
manages a separate thread (class) |
Functions managing the current thread | |
Defined in namespace
this_thread | |
(C++11) |
suggests that the implementation reschedule execution of threads (function) |
(C++11) |
returns the thread id of the current thread (function) |
(C++11) |
stops the execution of the current thread for a specified time duration (function) |
(C++11) |
stops the execution of the current thread until a specified time point (function) |
쓰레드 취소The
|
(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) |
(C++11) |
provides mutual exclusion facility which implements locking with a timeout (class) |
(C++11) |
provides mutual exclusion facility which can be locked recursively by the same thread (class) |
(C++11) |
provides mutual exclusion facility which can be locked recursively by the same thread and implements locking with a timeout (class) |
<shared_mutex> 헤더에 정의됨. | |
(C++14) |
provides shared mutual exclusion facility (class) |
Generic mutex management | |
<mutex> 헤더에 정의됨. | |
(C++11) |
implements a strictly scope-based mutex ownership wrapper (class template) |
(C++17) |
deadlock-avoiding RAII wrapper for multiple mutexes (class template) |
(C++11) |
implements movable mutex ownership wrapper (class template) |
(C++14) |
implements movable shared mutex ownership wrapper (class template) |
(C++11) (C++11) (C++11) |
tag type used to specify locking strategy (class) |
(C++11) (C++11) (C++11) |
tag constants used to specify locking strategy (constant) |
Generic locking algorithms | |
(C++11) |
attempts to obtain ownership of mutexes via repeated calls to try_lock (function template) |
(C++11) |
locks specified mutexes, blocks if any are unavailable (function template) |
Call once | |
(C++11) |
helper object to ensure that call_once invokes the function only once (class) |
(C++11) |
invokes a function only once even if called from multiple threads (function template) |
[편집] 조건 변수
조건변수(condition variable)는 동기화 기본형으로 여러 쓰레드가 서로 통신할 수 있도록 한다. 이를 이용하면 일부 쓰레드가 작업 중인 다른 쓰레드로 부터의 작업 통지를 기다릴 수 있다(타임아웃 시간을 설��할 수 도 있다.) 조건변수는 항상 뮤텍스와 연관된다.
틀:cpp/thread/dsc notify all at thread exit틀:cpp/thread/dsc cv status <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) |
SemaphoresA 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
Latches and BarriersLatches 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
|
(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) |
(C++11) |
packages a function to store its return value for asynchronous retrieval (class template) |
(C++11) |
waits for a value that is set asynchronously (class template) |
(C++11) |
waits for a value (possibly referenced by other futures) that is set asynchronously (class template) |
(C++11) |
runs a function asynchronously (potentially in a new thread) and returns a std::future that will hold the result (function template) |
(C++11) |
specifies the launch policy for std::async (enum) |
(C++11) |
specifies the results of timed waits performed on std::future and std::shared_future (enum) |
Future errors | |
(C++11) |
reports an error related to futures or promises (class) |
(C++11) |
identifies the future error category (function) |
(C++11) |
identifies the future error codes (enum) |
[편집] See also
C documentation for Thread support library
|