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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With