std::thread(3)

πŸ’– NAME πŸ’–

std::thread β€” that's the name, bestie. This page is chilling in the Library Functions Manual, section 3, and it's giving C++ concurrency royalty. πŸ‘‘


✨ SYNOPSIS ✨

#include <thread>

πŸŽ€ Classes πŸŽ€

  • class id

πŸ¦‹ Public Types πŸ¦‹

  • using native_handle_type

✨ Public Member Functions ✨

  • the big constructor that starts a whole new thread:
       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
(Note that these are not member symbols.)
  • bool operator== (thread::id __x, thread::id __y) noexcept
  • void swap (thread &__x, thread &__y) noexcept

πŸ’« Detailed Description πŸ’«

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

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. ⚠️ like, the WHOLE process, bestie β€” not a vibe, not a glitch, just termination.

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.


mwah πŸ’‹ this lil page came from libstdc++ and lives at std::thread(3). The footer has no date, so we're just gonna say it's giving libstdc++ + std::thread(3) and leave it iconic. 🫢

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms