32 Thread support library [thread]

32.4 Threads [thread.threads]

32.4.3 Class jthread [thread.jthread.class]

32.4.3.2 Members [thread.jthread.mem]

void swap(jthread& x) noexcept;
Effects: Exchanges the values of *this and x.
[[nodiscard]] bool joinable() const noexcept;
Returns: get_Β­id() != id().
void join();
Effects: Blocks until the thread represented by *this has completed.
Synchronization: The completion of the thread represented by *this synchronizes with ([intro.multithread]) the corresponding successful join() return.
Note
:
Operations on *this are not synchronized.
β€” end note
 ]
Postconditions: The thread represented by *this has completed.
get_Β­id() == id().
Throws: system_Β­error when an exception is required ([thread.req.exception]).
Error conditions:
  • resource_Β­deadlock_Β­would_Β­occur β€” if deadlock is detected or get_Β­id() == this_Β­thread​::​​get_Β­id().
  • no_Β­such_Β­process β€” if the thread is not valid.
  • invalid_Β­argument β€” if the thread is not joinable.
void detach();
Effects: The thread represented by *this continues execution without the calling thread blocking.
When detach() returns, *this no longer represents the possibly continuing thread of execution.
When the thread previously represented by *this ends execution, the implementation releases any owned resources.
Postconditions: get_Β­id() == id().
Throws: system_Β­error when an exception is required ([thread.req.exception]).
Error conditions:
  • no_Β­such_Β­process β€” if the thread is not valid.
  • invalid_Β­argument β€” if the thread is not joinable.
id get_id() const noexcept;
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.