命名空间
变体
操作

std::thread::~thread

来自 cppreference.cn
< cpp‎ | thread‎ | thread
 
 
并发支持库
线程
(C++11)
(C++20)
this_thread 命名空间
(C++11)
(C++11)
(C++11)
协同取消
互斥
(C++11)
通用锁管理
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
条件变量
(C++11)
信号量
门闩和屏障
(C++20)
(C++20)
期值
(C++11)
(C++11)
(C++11)
(C++11)
安全回收
(C++26)
危险指针
原子类型
(C++11)
(C++20)
原子类型的初始化
(C++11)(C++20 中已弃用)
(C++11)(C++20 中已弃用)
内存排序
(C++11)(C++26 中已弃用)
原子操作的自由函数
原子标志的自由函数
 
 
~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 的公开成员函数) [编辑]
English Deutsch 日本語 한국어 中文(简体) 中文(繁體)