33 Concurrency support library [thread]

33.4 Threads [thread.threads]

33.4.3 Class thread [thread.thread.class] Constructors [thread.thread.constr]

thread() noexcept;
Effects: The object does not represent a thread of execution.
Postconditions: get_­id() == id().
template<class F, class... Args> explicit thread(F&& f, Args&&... args);
Constraints: remove_­cvref_­t<F> is not the same type as thread.
Mandates: The following are all true:
  • is_­constructible_­v<decay_­t<F>, F>,
  • (is_­constructible_­v<decay_­t<Args>, Args> && ...), and
  • is_­invocable_­v<decay_­t<F>, decay_­t<Args>...>.
Effects: The new thread of execution executes invoke(auto(std::forward<F>(f)), // for invoke, see [func.invoke] auto(std::forward<Args>(args))...) 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]).
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.