I've got several long running boost threads that I want to be able to shut down by interrupting them. All of the documentation I can find says that you can catch the thread_interrupted
exception, but it doesn't really say what happens if you don't.
I would assume it kills the thread (and hopefully the thread gets properly cleaned up). But then does the exception die off with the thread? Or does it get passed up to the main thread and kill it too?
The exception is just like any other C++ exception. If you choose not to catch it, it will cause the same effect as any other unhandled exception.
If left uncaught, it will not propagate to the main thread, but could cause other undesirable behaviour. On Visual C++, by default this will terminate your process, for example.
In general, defensive programming practice would dictate that you should catch any exception your code can throw - just the same as you would check for error from an OS API that you called.
There's a backgrounder on interruption here by the person who wrote a lot of the Boost.Thread code.
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