Namespaces
Variants

std::jthread:: ~jthread

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
~jthread ( ) ;
(自 C++20 起)

销毁 jthread 对象。

* this 关联有执行线程( joinable ( ) == true ),则调用 request_stop() 后接着调用 join()

注释

如果 jthread 先前已被请求停止,则 request_stop() 不会产生任何效果。

一个 jthread 对象在以下情况下不再关联线程:

  • 它是默认构造的。
  • 它已被移出。
  • 已调用 join()
  • 已调用 detach()

如果 join() 抛出异常(例如检测到死锁),可能会调用 std::terminate()

示例

参见

析构线程对象,底层线程必须已被合并或分离
( std::thread 的公开成员函数)