std::thread(3cxx)
bestie, youβve landed on std::thread(3cxx) from the libstdc++ manual. Itβs giving C++ thread class main character energy, and weβre gonna get through every single line together. π«Άπ
π NAME π
std::thread β thatβs the name, bestie. Short, iconic, no notes. π
β¨ SYNOPSIS β¨
#include <thread>
π Classes π
class id
π¦ Public Types π¦
using native_handle_type = __gthread_t
πΈ Public Member Functions πΈ
Okay so the templated constructor is highkey the star of the show, and itβs exactly this:
template<typename _Callable , typename... _Args, typename =
_Require<__not_same<_Callable>>> thread (_Callable &&__f, _Args
&&... __args)
The rest of the public member function roster, fr fr:
thread (const thread &)=deletethread (thread &&__t) noexceptvoid detach ()id get_id () const noexceptvoid join ()bool joinable () const noexceptnative_handle_type native_handle ()thread & operator= (const thread &)=deletethread & operator= (thread &&__t) noexceptvoid 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 π«
Okay so a std::thread represents a new thread of execution. Thatβs the whole vibe. π§΅
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. π Not me being obsessed with ownership transfer, but here we are.
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. Not a vibe check you want to fail, bestie β thatβs a whole-process termination. π
π Since π
C++11
πΈ Member Function Documentation πΈ
π«Ά native_handle_type std::thread::native_handle () [inline] π«Ά
π Precondition π
thread is joinable β thatβs the condition, no cap.
π Author π
Generated automatically by Doxygen for libstdc++ from the source code.
Yup, the robots generated it β weβre just giving it the group-chat remix. π€π
footer check, bestie: this is from libstdc++, and the manual page is std::thread(3cxx). The original footer doesnβt list a date, so Iβm not inventing one β periodt. πβ¨
π¦ where this page comes from
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms