c++ - 检查 std::thread 是否仍在运行

标签 c++ multithreading

<分区>

有没有办法确定线程是否仍在运行?由于多种原因,我无法使用 std::futurestd::async

我想到了某种带有超时的 join,例如尝试加入一个线程3秒,如果成功则认为线程结束,否则认为正在运行。

最佳答案

最接近的是std::thread::joinable() .从引用文献中引用:

Checks if the thread object identifies an active thread of execution. Specifically, returns true if get_id() != std::thread::id(). So a default constructed thread is not joinable.
A thread that has finished executing code, but has not yet been joined is still considered an active thread of execution and is therefore joinable.

关于c++ - 检查 std::thread 是否仍在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33943601/

相关文章:

c++ - line.find 不会编译,行未声明

c++ - 如果模板 arg 是 const,则将 const 添加到类型

C++ 递归搜索函数(学校作业)

multithreading - Option [Object]上的Scala匹配未完全包含Some(o),Akka中没有None接收函数

multithreading - 如何在 Iron 框架中启用线程功能?

java - 使用 CompletableFuture 的建议

c++ - 从(csv)的测试文件中读取并存储到房间对象中

c++ - 计数循环?

python - 在 Python 中线程多个 SQL 查询的良好实践/设计是什么

ios - Realm 线程困惑