std::thread::~thread(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

std::thread::~thread - std::thread::~thread

okay bestie, this is the std::thread::~thread page from the C++ Standard Libary manual, and we are officially in destructor territory πŸ’…βœ¨


✨ Synopsis ✨

~thread();  (since C++11)

Destroys the thread object. That’s the job. That’s the whole vibe. πŸŽ€

⚠️ If *this has an associated thread (joinable() == true), std::terminate() is called. Like… not a drill, bestie. πŸ˜­πŸ’€

πŸ¦‹ Notes πŸ¦‹

A thread object does not have an associated thread (and is safe to destroy) after:

  • it was default-constructed.
  • it was moved from.
  • join() has been called.
  • detach() has been called.

so like, those are the green flags for destroying it safely 🫢✨


🌸 Example 🌸

       // Run this code

        #include <thread>
        using namespace std::chrono_literals;

        int main()
        {
            auto bleah = std::thread{[]{ std::this_thread::sleep_for(13ms); }};

        }   // ~thread calls std::terminate()

πŸ“ Possible output πŸ“

        terminate called without an active exception

πŸ‘‘ See also πŸ‘‘

  • destructor β€” if the thread is joinable, then a stop is requested and the thread joins (public member function of std::jthread) πŸ’œ

k bye bestie, source/version is http://cppreference.com, dated 2024.06.10 β€” stay joined or get terminated, iykyk πŸŒˆπŸ’…πŸ«Ά

πŸ“¦ where this page comes from