Files
2025-10-25 03:02:53 +03:00

144 lines
4.0 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[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.2Multi-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.2Exceptions"))[.](#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.2Exceptions"))[.](#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)