144 lines
4.0 KiB
Markdown
144 lines
4.0 KiB
Markdown
[thread.jthread.mem]
|
||
|
||
# 32 Concurrency support library [[thread]](./#thread)
|
||
|
||
## 32.4 Threads [[thread.threads]](thread.threads#thread.jthread.mem)
|
||
|
||
### 32.4.4 Class jthread [[thread.jthread.class]](thread.jthread.class#thread.jthread.mem)
|
||
|
||
#### 32.4.4.3 Members [thread.jthread.mem]
|
||
|
||
[ð](#lib:swap,jthread)
|
||
|
||
`void swap(jthread& x) noexcept;
|
||
`
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L2131)
|
||
|
||
*Effects*: Exchanges the values of *this and x[.](#1.sentence-1)
|
||
|
||
[ð](#lib:joinable,jthread)
|
||
|
||
`bool joinable() const noexcept;
|
||
`
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L2142)
|
||
|
||
*Returns*: get_id() != id()[.](#2.sentence-1)
|
||
|
||
[ð](#lib:join,jthread)
|
||
|
||
`void join();
|
||
`
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L2153)
|
||
|
||
*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#L2158)
|
||
|
||
*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 successful join() 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#L2167)
|
||
|
||
*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#L2172)
|
||
|
||
*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#L2176)
|
||
|
||
*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,jthread)
|
||
|
||
`void detach();
|
||
`
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L2194)
|
||
|
||
*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#L2203)
|
||
|
||
*Postconditions*: get_id() == id()[.](#9.sentence-1)
|
||
|
||
[10](#10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L2207)
|
||
|
||
*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#L2211)
|
||
|
||
*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,jthread)
|
||
|
||
`id get_id() const noexcept;
|
||
`
|
||
|
||
[12](#12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L2225)
|
||
|
||
*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)
|