If un-unhandled exception is causing the execution of the interrupted thread to terminate, why program is not crashing and coming out of following loop in main()
Simply because that's how Boost.Thread was designed to operate.
They've made it so that interrupt()
will throw an exception, and failing to catch the exception terminates the thread (but not the process).
Nothing in the documentation, either that which you've quoted, or that which can be found elsewhere, says that your program should be expected to crash.
From the documentation:
A running thread can be interrupted by invoking the interrupt() member function of the corresponding boost::thread object. When the interrupted thread next executes one of the specified interruption points (or if it is currently blocked whilst executing one) with interruption enabled, then a boost::thread_interrupted exception will be thrown in the interrupted thread. If not caught, this will cause the execution of the interrupted thread to terminate.
and:
If the function or callable object passed to the boost::thread constructor propagates an exception when invoked that is not of type boost::thread_interrupted, std::terminate() is called.
Presumably they just catch that kind of exception in the code that invokes your thread entrypoint, and return safely, ending the thread. Thus, although you didn't handle the exception, it's not an unhandled exception as far as C++ is concerned.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…