bool joinable() const noexcept;
|
(C++11 起) | |
检查 thread 对象是否标识活跃的执行线程。具体是返回 true if get_id() != std::thread::id() 。故默认构造的 thread 不可合并。
完成执行代码,但未被合并的线程仍被认为是活跃线程,从而可合并。
目录 |
(无)
若 thread 对象标识活跃的执行线程则为 true ,否则为 false
#include <iostream> #include <thread> #include <chrono> void foo() { std::this_thread::sleep_for(std::chrono::seconds(1)); } int main() { std::thread t; std::cout << "before starting, joinable: " << t.joinable() << '\n'; t = std::thread(foo); std::cout << "after starting, joinable: " << t.joinable() << '\n'; t.join(); std::cout << "after joining, joinable: " << t.joinable() << '\n'; }
输出:
before starting, joinable: 0 after starting, joinable: 1 after joining, joinable: 0
返回线程的 id (公开成员函数) |
|
等待线程完成其执行 (公开成员函数) |
|
容许线程从线程句柄独立开来执行 (公开成员函数) |