std::thread:: ~thread
From cppreference.net
C++
Concurrency support library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
~thread
(
)
;
|
(C++11 起) | |
销毁线程对象。
若 * this 关联有执行线程( joinable ( ) == true ),则将调用 std:: terminate ( ) 。
注释
当线程对象满足以下条件时,它不再关联实际执行线程(此时销毁是安全的):
示例
运行此代码
#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
的公开成员函数)
|