[thread.thread.member]

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

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

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

#### 32.4.3.6 Members [thread.thread.member]

[ð](#lib:swap,thread)

`void swap(thread& x) noexcept;
`

[1](#1)

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

*Effects*: Swaps the state of *this and x[.](#1.sentence-1)

[ð](#lib:joinable,thread)

`bool joinable() const noexcept;
`

[2](#2)

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

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

[ð](#lib:join,thread)

`void join();
`

[3](#3)

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

*Effects*: Blocks until the thread represented by *this has completed[.](#3.sentence-1)

[4](#4)

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

*Synchronization*: The completion of the thread represented by *this synchronizes with ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))
the corresponding successfuljoin() return[.](#4.sentence-1)

[*Note [1](#note-1)*:

Operations on*this are not synchronized[.](#4.sentence-2)

â *end note*]

[5](#5)

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

*Postconditions*: The thread represented by *this has completed[.](#5.sentence-1)

get_id() == id()[.](#5.sentence-2)

[6](#6)

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

*Throws*: system_error when
an exception is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#6.sentence-1)

[7](#7)

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

*Error conditions*: 

- [(7.1)](#7.1)

  resource_deadlock_would_occur â if deadlock is detected orget_id() == this_thread​::​​get_id()[.](#7.1.sentence-1)

- [(7.2)](#7.2)

  no_such_process â if the thread is not valid[.](#7.2.sentence-1)

- [(7.3)](#7.3)

  invalid_argument â if the thread is not joinable[.](#7.3.sentence-1)

[ð](#lib:detach,thread)

`void detach();
`

[8](#8)

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

*Effects*: The thread represented by *this continues execution without the calling thread
blocking[.](#8.sentence-1)

When detach() returns, *this no longer represents the possibly continuing
thread of execution[.](#8.sentence-2)

When the thread previously represented by *this ends execution, the
implementation releases any owned resources[.](#8.sentence-3)

[9](#9)

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

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

[10](#10)

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

*Throws*: system_error when
an exception is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#10.sentence-1)

[11](#11)

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

*Error conditions*: 

- [(11.1)](#11.1)

  no_such_process â if the thread is not valid[.](#11.1.sentence-1)

- [(11.2)](#11.2)

  invalid_argument â if the thread is not joinable[.](#11.2.sentence-1)

[ð](#lib:get_id,thread)

`id get_id() const noexcept;
`

[12](#12)

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

*Returns*: A default constructed id object if *this does not represent a thread,
otherwise this_thread​::​get_id() for the thread of execution represented by*this[.](#12.sentence-1)
