Construct a std::thread object associated with
a new thread of execution.
template<typename Callable,typename Args...> explicit thread(Callable func,Args... args);
- Preconditions:
funcand each element ofargsmust beMoveConstructible- Effects:
Constructs a
std::threadinstance, and associates it with a newly-created thread of execution. Copies or movesfuncandargsinto internal storage associated that persists for the lifetime of the new thread of execution. Runs the supplied functionfuncon that new thread of execution by INVOKE(func,args).- Postconditions:
For a newly-constructed
std::threadobjectx,x.get_id()!=id().- Throws:
An exception of type
std::system_errorif unable to start the new thread. Any exception thrown by copyingfuncorargsinto internal storage.- Synchronization:
The invocation of the constructor happens-before the execution of the supplied function on the newly-created thread of execution.
- Note:
On compilers that don't support variadic templates, an overloaded set of constructors is provided that supports passing of up to 5 arguments.
Header
#include <thread>