32 Concurrency support library [thread]

32.4 Threads [thread.threads]

32.4.3 Class thread [thread.thread.class]

32.4.3.4 Constructors [thread.thread.constr]

thread() noexcept;
Effects: The object does not represent a thread of execution.
Postconditions: get_id() == id().
template<class... Args> explicit thread(Args&&... args);
Constraints:
  • Args is not an empty pack, and
  • remove_cvref_t<Args...[0]> is not the same type as thread.
Let i be the smallest value such that decay_t<Args...[i]> is not a thread attribute type, if such a value exists.
Then the following notation is used:
  • Let F be Args...[i].
  • Let f be args...[i].
  • Let Attrs be a pack of the types Args...[j] for each j such that .
  • Let attrs be a pack of the expressions args...[j] for each j such that .
  • Let FArgs be a pack of the types Args...[j] for each j such that .
  • Let fargs be a pack of the expressions args...[j] for each j such that .
Mandates: The value i exists, and the following are all true:
  • is_constructible_v<decay_t<F>, F>,
  • (is_constructible_v<decay_t<FArgs>, FArgs> && ...),
  • is_invocable_v<decay_t<F>, decay_t<FArgs>...>, and
  • no type is present more than once in the pack remove_cvref_t<Attrs>.
Effects: The new thread of execution executes invoke(auto(std::forward<F>(f)), // for invoke, see [func.invoke] auto(std::forward<FArgs>(fargs))...) with the values produced by auto being materialized ([conv.rval]) in the constructing thread.
Any return value from this invocation is ignored.
[Note 1: 
This implies that any exceptions not thrown from the invocation of the copy of f will be thrown in the constructing thread, not the new thread.
— end note]
If the invocation of invoke terminates with an uncaught exception, terminate is invoked ([except.terminate]).
[Note 2: 
The parameters attrs... can affect the behavior of the new thread ([thread.attributes]).
— end note]
Synchronization: The completion of the invocation of the constructor synchronizes with the beginning of the invocation of the copy of f.
Postconditions: get_id() != id().
*this represents the newly started thread.
Throws: system_error if unable to start the new thread.
Error conditions:
  • resource_unavailable_try_again — the system lacked the necessary resources to create another thread, or the system-imposed limit on the number of threads in a process would be exceeded.
thread(thread&& x) noexcept;
Postconditions: x.get_id() == id() and get_id() returns the value of x.get_id() prior to the start of construction.