Thread API
You start out with 99 problems, fix one and have 101 left
You start out with 99 problems, fix one and have 101 left
This is the page is about the thread support in C++ 11. For other API's and languages look at the sub pages (Thread API Windows).
Thread support library
std::thread
The class represents a single thread of execution.
join : waits for a thread to finish its execution
detach : Make the thread execute independently from the thread handle.
get_id : Get the id of the thread
native_handle : Get the native handle of the thread.
hardware_concurrency : Return number of concurrent threads supported
std::this_thread
Namespace functions related to the current running thread.
std::thread::id get_id() : Return a id for the current thread.
yield(): Hint that the thread has nothing more to do right now and can be put to sleep.
std::mutex
Limit access to a shared resources.
lock - Locks mutex, blocks if mutex is not available.
try_lock - Try to lock the mutex, returns false if mutex not available.
unlock - Unlocks the mutex
Atomic operations library
std::atomic
std::memory_order
Reference
C++11 threads, affinity and hyperthreading - 2016
How Ubisoft Montreal Develops Games For Multicore – Before and After C++11. - 2014
Double-Checked Locking Is Fixed In C++11 - 2013
Acquire and Release Fences Don’t Work the Way You’d Expect - 2013
The Synchronizes-With Relation - 2013
Acquire and Release Fences - 2013
Acquire and Release Semantics - 2012
Programming with Threads: Questions Frequently Asked by C and C++ Programmers
C++11 Language Extensions — Concurrency
Better Code: Concurrency - 2019
Advanced thread pool - 2019
Fast semaphore - 2019
Simple thread pool - 2019
Fast mutex - 2019
Read/write mutex - 2019
Synchronizing with atomics - 2019
Atomic blocking queue - 2019
Memory barriers and thread synchronization - 2019
atomic<> Weapons - 2019
Dekker’s algorithm - 2019
Dekker’s algorithm for N threads - 2019
C++11 threads, affinity and hyperthreading - 2016
The promises and challenges of std::async task-based parallelism in C++11 - 2016