std::this_thread::get_id(3)
Okay bestie, this is the std::this_thread::get_id(3) page from the C++ Standard Libary manual π (yes, that spelling is canon, donβt come for me). Itβs short, itβs sweet, itβs literally βwhich thread am I?β energy.
β¨ NAME β¨
std::this_thread::get_id - std::this_thread::get_id β yes bestie, thatβs the whole name, twice. Itβs giving βfunction so iconic they named it twiceβ π
.
π Synopsis π
Defined in header <thread>:
std::thread::id get_id() noexcept; (since C++11)
Returns the id of the current thread. Thatβs it. Thatβs the whole serve π«Ά.
π Parameters π
- (none) β not a single parameter, zero, zilch, nada β¨.
π¦ Return value π¦
The id of the current thread. Main-character thread identification, periodt π.
π₯ Example π₯
// Run this code
#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:
thread 140113018054400 sleeping...
thread 140113009661696 sleeping...
π See also π
get_idreturns the id of the thread β public member function ofstd::threadπ- C documentation for
thrd_currentπ
Cute sign-off: source/version/date is http://cppreference.com, 2024.06.10 β mwah, go forth and identify your thread, bestie ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms