I'm using boost::thread join
method to wait until thread is finished. But if I try to join
the thread when it already finished I receive an exception. So how can I:
Join thread if active and do nothing if not active?
Use the joinable()
function to check whether it should be joined:
if (thread.joinable()) thread.join();
You can (in fact, you must) join a thread even if it's already finished, unless it's been detached. It's an error to join it twice, or to join an empty or detached thread.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.