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::id

id(); (since C++11) Default-constructs a new thread identifier. The identifier does not represent a thread. Parameters (none). Exceptions noexcept specification: noexcept

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::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::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

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::this_thread::yield

Defined in header <thread> void yield(); (since C++11) Provides a hint to the implementation to reschedule the execution of threads, allowing other threads to run. Parameters (none). Return value (none). Notes The exact behavior of this function depends on the implementation, in particular on the mechanics of the OS scheduler in use and the state of the system. For example, a first-in-first-out realtime scheduler (SCHED_FIFO in Linux) would suspend the current thre

std::this_thread::sleep_until

Defined in header <thread> template< class Clock, class Duration > void sleep_until( const std::chrono::time_point<Clock,Duration>& sleep_time ); (since C++11) Blocks the execution of the current thread until specified sleep_time has been reached. The clock tied to sleep_time is used, which means that adjustments of the clock are taken into account. Thus, the duration of the block might, but might not, be less or more than sleep_time - Clock::now() at the ti