[thread.thread.constr]

# 32 Concurrency support library [[thread]](./#thread)

## 32.4 Threads [[thread.threads]](thread.threads#thread.thread.constr)

### 32.4.3 Class thread [[thread.thread.class]](thread.thread.class#thread.thread.constr)

#### 32.4.3.3 Constructors [thread.thread.constr]

[ð](#lib:thread,constructor)

`thread() noexcept;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1655)

*Effects*: The object does not represent a thread of execution[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1659)

*Postconditions*: get_id() == id()[.](#2.sentence-1)

[ð](#lib:thread,constructor_)

`template<class F, class... Args> explicit thread(F&& f, Args&&... args);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1670)

*Constraints*: remove_cvref_t<F> is not the same type as thread[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1674)

*Mandates*: The following are all true:

- [(4.1)](#4.1)

is_constructible_v<decay_t<F>, F>,

- [(4.2)](#4.2)

(is_constructible_v<decay_t<Args>, Args> && ...), and

- [(4.3)](#4.3)

is_invocable_v<decay_t<F>, decay_t<Args>...>[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1683)

*Effects*: The new thread of execution executesinvoke(auto(std::forward<F>(f)), // for invoke, see [[func.invoke]](func.invoke "22.10.5 invoke functions")auto(std::forward<Args>(args))...) with the values produced by auto being materialized ([[conv.rval]](conv.rval "7.3.5 Temporary materialization conversion")) in the constructing thread[.](#5.sentence-1)

Any return value from this invocation is ignored[.](#5.sentence-2)

[*Note [1](#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[.](#5.sentence-3)

â *end note*]

If the invocation of invoke terminates with an uncaught exception,terminate is invoked ([[except.terminate]](except.terminate "14.6.2 The std​::​terminate function"))[.](#5.sentence-4)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1700)

*Synchronization*: The completion of the invocation of the constructor
synchronizes with the beginning of the invocation of the copy of f[.](#6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1705)

*Postconditions*: get_id() != id()[.](#7.sentence-1)

*this represents the newly started thread[.](#7.sentence-2)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1709)

*Throws*: system_error if unable to start the new thread[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1713)

*Error conditions*: 

- [(9.1)](#9.1)

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[.](#9.sentence-1)

[ð](#lib:thread,constructor__)

`thread(thread&& x) noexcept;
`

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L1728)

*Postconditions*: x.get_id() == id() and get_id() returns the
value of x.get_id() prior to the start of construction[.](#10.sentence-1)
