Namespaces
Variants

std::thread:: ~thread

From cppreference.net
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
~thread ( ) ;
(C++11以降)

スレッドオブジェクトを破棄します。

* this に関連付けられたスレッドがある場合( joinable ( ) == true )、 std:: terminate ( ) が呼び出されます。

注記

スレッドオブジェクトは、以下の場合に関連するスレッドを持たず(安全に破棄可能):

  • デフォルト構築された場合。
  • ムーブされた場合。
  • join() が呼び出された場合。
  • detach() が呼び出された場合。

#include <thread>
using namespace std::chrono_literals;
int main()
{
    auto bleah = std::thread{[]{ std::this_thread::sleep_for(13ms); }};
}   // ~thread calls std::terminate()

出力例:

terminate called without an active exception

関連項目

スレッドが結合可能な場合、停止要求が行われ、スレッドが結合される
( std::jthread の公開メンバ関数 )