# std::this_thread::get_id

> C++ Atlas: `cppatlas.com/w/cpp/thread/get_id` | Source: https://en.cppreference.com/w/cpp/thread/get_id | Domain: Concurrency support | Standards: C++11

Returns the id of the current thread.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <thread>
std::thread::id get_id() noexcept; // (since C++11)
```

Returns the *id* of the current thread.

### Parameters

(none)

### Return value

*id* of the current thread.

### Example

```cpp
#include <chrono>
#include <iostream>
#include <syncstream>
#include <thread>
using namespace std::chrono_literals;

void foo()
{
    std::thread::id this_id = std::this_thread::get_id();

    std::osyncstream(std::cout) << "thread " << this_id << " sleeping...\n";

    std::this_thread::sleep_for(500ms);
}

int main()
{
    std::jthread t1{foo};
    std::jthread t2{foo};
}
```

Possible output:

```text
thread 140113018054400 sleeping...
thread 140113009661696 sleeping...
```

### See also

- [`get_id`](https://en.cppreference.com/w/cpp/thread/thread/get_id): returns the *id* of the thread (public member function of `std::thread`)
- [C documentation for `thrd_current`](https://en.cppreference.com/w/c/thread/thrd_current)

---
Attribution: content from https://en.cppreference.com/w/cpp/thread/get_id (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.