std::thread::thread (3) - Linux Man Pages
thread() noexcept; (1) (since C++11)
thread( thread&& other ) noexcept; (2) (since C++11)
template< class Function, class... Args > (3) (since C++11)
explicit thread( Function&& f, Args&&... args );
thread(const thread&) = delete; (4) (since C++11)
Constructs new thread object.
1) Creates new thread object which does not represent a thread.
2) Move constructor. Constructs the thread object to represent the thread of execution that was represented by other. After this call other no longer represents a thread of execution.
3) Creates new std::thread object and associates it with a thread of execution. The new thread of execution starts executing
where decay_copy is defined as
Except that the calls to decay_copy are evaluated in the context of the caller, so that any exceptions thrown during evaluation and copying/moving of the arguments are thrown in the current thread, without starting the new thread.
The completion of the invocation of the constructor synchronizes-with (as defined in std::memory_order) the beginning of the invocation of the copy of f on the new thread of execution.
This constructor does not participate in overload resolution if std::decay_t<Function> is the same type as std::thread. (since C++14)
4) The copy constructor is deleted; threads are not copyable. No two std::thread objects may represent the same thread of execution.
other - another thread object to construct this thread object with
f - Callable object to execute in the new thread
args... - arguments to pass to the new function
1) get_id() equal to std::thread::id() (i.e. joinable is false)
2) other.get_id() equal to std::thread::id() and get_id() returns the value of other.get_id() prior to the start of construction
3) get_id() not equal to std::thread::id() (i.e. joinable is true)
3) std::system_error if the thread could not be started. The exception may represent the error condition std::errc::resource_unavailable_try_again or another implementation-specific error condition.
The arguments to the thread function are moved or copied by value. If a reference argument needs to be passed to the thread function, it has to be wrapped (e.g. with std::ref or std::cref).
Any return value from the function is ignored. If the function throws an exception, std::terminate is called. In order to pass return values or exceptions back to the calling thread, std::promise or std::async may be used.
// Run this code