---
name: "std::thread"
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::thread/3cxx"
---

# std::thread(3cxx)

## NAME

std::thread

## SYNOPSIS

`#include <thread>`

### Classes

class **id**\

### Public Types

**using** **\_State\_ptr** = **unique\_ptr**\< \_State \>\
 **using** **native\_handle\_type** = \_\_gthread\_t\

### Public Member Functions

template\<**typename** \_Callable , typename... \_Args, **typename**  = \_Require\<\_\_not\_same\<\_Callable\>\>\> **thread** (\_Callable &&\_\_f, **\_Args** &&... **\_\_args**)\
 **thread** (const **thread** &)=**delete**\
 **thread** (**thread** &&\_\_t) noexcept\
 **void** **detach** ()\
 **id** **get\_id** () const noexcept\
 **void** **join** ()\
 bool **joinable** () const noexcept\
 native\_handle\_type **native\_handle** ()\
 **thread** & **operator=** (const **thread** &)=**delete**\
 **thread** & **operator=** (**thread** &&\_\_t) noexcept\
 **void** **swap** (**thread** &\_\_t) noexcept\

### Static Public Member Functions

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

### Related Symbols

(Note that these are not member symbols.)  **void** **swap** (**thread** &\_\_x, **thread** &\_\_y) noexcept\

## Detailed Description

A std::thread represents a new thread of execution.

The default constructor creates an object that does not own a thread. The `thread(F&&, Args&&...)` constructor invokes a callable in a new thread, and owns that new thread. A `std::thread` that owns a thread is *joinable*. Joining a thread waits for it to finish executing, which happens when the callable running in that thread returns.

A `std::thread` cannot be copied, but can be moved. Moving a joinable object transfers ownership of its thread to another object.

A joinable `std::thread` must be explicitly joined (or detached) before it is destroyed or assigned to. Attempting to destroy a joinable thread will terminate the whole process.

**Since**

C++11

## Member Function Documentation

### native\_handle\_type std::thread::native\_handle ()` [inline]`

**Precondition**

thread is joinable

## Author

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