How can I tell reliably if a boost thread has exited its run method?

后端 未结 7 1040
情歌与酒
情歌与酒 2020-12-01 13:40

I assumed joinable would indicate this, however, it does not seem to be the case.

In a worker class, I was trying to indicate that it was still processing through a

7条回答
  •  醉话见心
    2020-12-01 14:40

    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.

提交回复
热议问题