std::thread::joinable

bool joinable() const; (since C++11) Checks if the thread object identifies an active thread of execution. Specifically, returns true if get_id() != std::thread::id(). So a default constructed thread is not joinable. A thread that has finished executing code, but has not yet been joined is still considered an active thread of execution and is therefore joinable. Parameters (none). Return value true if the thread object identifies an active thread of execution, false otherwise. E

std::thread::join

void join(); (since C++11) Blocks the current thread until the thread identified by *this finishes its execution. Parameters (none). Return value (none). Postconditions joinable is false. Exceptions std::system_error if an error occurs. Error Conditions resource_deadlock_would_occur if this->get_id() == std::this_thread::get_id() (deadlock detected) no_such_process if the thread is not valid invalid_argument if joinable is false Example #include <iostre

std::thread::id

Defined in header <thread> class thread::id; (since C++11) The class thread::id is a lightweight, trivially copyable class that serves as a unique identifier of std::thread objects. Instances of this class may also hold the special distinct value that does not represent any thread. Once a thread has finished, the value of std::thread::id may be reused by another thread. This class is designed for use as key in associative containers, both ordered and unordered. Member fun

std::thread::native_handle

native_handle_type native_handle(); (since C++11) Returns the implementation defined underlying thread handle. Parameters (none). Return value implementation defined handle type representing the thread. Exceptions (none). Example Uses native_handle to enable realtime scheduling of C++ threads on a POSIX system. #include <thread> #include <mutex> #include <iostream> #include <chrono> #include <cstring> #include <pthread.h> std::mutex iom

std::thread

Defined in header <thread> class thread; (since C++11) The class thread represents a single thread of execution. Threads allow multiple pieces of code to run asynchronously and simultaneously. std::thread objects may also be in the state that does not represent any thread (it gets into that state after default construction, a move from, detach, or join), and a thread of execution may be not associated with any thread objects (it gets into that state after detach). No two st

std::thread::get_id

std::thread::id get_id() const; (since C++11) Returns a value of std::thread::id identifying the thread associated with *this. Parameters (none). Return value A value of type std::thread::id identifying the thread associated with *this. If there is no thread associated, default constructed std::thread::id is returned. Exceptions noexcept specification: noexcept Example #include <iostream> #include <thread> #include <chrono> void foo() { std::this_

std::thread::detach

void detach(); (since C++11) Separates the thread of execution from the thread object, allowing execution to continue independently. Any allocated resources will be freed once the thread exits. After calling detach *this no longer owns any thread. Parameters (none). Return value (none). Postconditions joinable is false. Exceptions std::system_error if joinable() == false or an error occurs. Example #include <iostream> #include <chrono> #include <thread>

std::thread::hardware_concurrency

static unsigned hardware_concurrency(); (since C++11) Returns the number of concurrent threads supported by the implementation. The value should be considered only a hint. Parameters (none). Return value number of concurrent threads supported. If the value is not well defined or not computable, returns ​0​. Exceptions noexcept specification: noexcept Example #include <iostream> #include <thread> int main() { unsigned int n = std::thread::hardware_concur

std::this_thread::get_id

Defined in header <thread> std::thread::id get_id(); (since C++11) Returns the id of the current thread. Parameters (none). Return value id of the current thread. Example #include <iostream> #include <thread> #include <chrono> #include <mutex> std::mutex g_display_mutex; void foo() { std::thread::id this_id = std::this_thread::get_id(); g_display_mutex.lock(); std::cout << "thread " << this_id << " sleep

std::terminate

Defined in header <exception> void terminate(); (until C++11) [[noreturn]] void terminate(); (since C++11) std::terminate() is called by the C++ runtime when exception handling fails for any of the following reasons: 1) an exception is thrown and not caught (it is implementation-defined whether any stack unwinding is done in this case) 2) an exception is thrown during exception handling (e.g. from a destructor of some local object, or from a function that had to be