我怎样才能知道是否可靠提振线程已退出其运行的方法? [英] How can I tell reliably if a boost thread has exited its run method?
问题描述
我以为可连接将表明这一点,但是,它似乎并不如此。
I assumed joinable would indicate this, however, it does not seem to be the case.
在工人类,我试图表明,它仍然在通过predicate处理:
In a worker class, I was trying to indicate that it was still processing through a predicate:
bool isRunning(){return thread_->joinable();}
那不是没有退出线程是可连接?我在想什么?是什么推动线程的含义::可连接?
Wouldn't a thread that has exited not be joinable? What am I missing... what is the meaning of boost thread::joinable?
推荐答案
既然你可以加入一个线程已终止后,甚至,可连接(),直到你调用连接()或分离(仍然会返回true)。如果你想知道如果一个线程仍在运行,你应该能够调用timed_join与0。注意等待时间,这可能会导致竞争状态,因为线程可以终止呼叫之后。
Since you can join a thread even after it has terminated, joinable() will still return true until you call join() or detach(). If you want to know if a thread is still running, you should be able to call timed_join with a wait time of 0. Note that this can result in a race condition since the thread may terminate right after the call.
这篇关于我怎样才能知道是否可靠提振线程已退出其运行的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!