---
name: "std::jthread"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::jthread"
---

# std::jthread(3cxx)

## NAME

std::jthread

## SYNOPSIS

`#include <thread>`

### Public Types

**using** **id** = **thread::id**\
 **using** **native\_handle\_type** = thread::native\_handle\_type\

### Public Member Functions

template\<**typename** \_Callable , typename... \_Args, **typename**  = enable\_if\_t\<!is\_same\_v\<remove\_cvref\_t\<\_Callable\>,					       jthread\>\>\> **jthread** (\_Callable &&\_\_f, **\_Args** &&... **\_\_args**)\
 **jthread** (const **jthread** &)=**delete**\
 **jthread** (**jthread** &&) noexcept=**default**\
 **void** **detach** ()\
 **id** **get\_id** () const noexcept\
 **stop\_source** **get\_stop\_source** () noexcept\
 **stop\_token** **get\_stop\_token** () const noexcept\
 **void** **join** ()\
 bool **joinable** () const noexcept\
 native\_handle\_type **native\_handle** ()\
 **jthread** & **operator=** (const **jthread** &)=**delete**\
 **jthread** & **operator=** (**jthread** &&\_\_other) noexcept\
 bool **request\_stop** () noexcept\
 **void** **swap** (**jthread** &\_\_other) noexcept\

### Static Public Member Functions

**static** unsigned **hardware\_concurrency** () noexcept\

### Friends

**void** **swap** (**jthread** &**\_\_lhs**, **jthread** &**\_\_rhs**) noexcept\

## Detailed Description

A thread with cancellation and automatic joining.

Unlike `std::thread`, destroying a joinable `std::jthread` will not terminate the process. Instead, it will try to request its thread to stop, then will join it.

A `std::jthread` has a `std::stop_source` member which will be passed as the first argument to the callable that runs in the new thread (as long as the callable will accept that argument). That can then be used to send a stop request that the new thread can test for.

**Since**

C++20

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
