[cxx-abi-dev] How to detect a forced unwind in a catch block?
Thiago Macieira
thiago at kde.org
Sat Sep 3 22:47:11 UTC 2016
Em sábado, 3 de setembro de 2016, às 10:21:07 CEST, Richard Smith escreveu:
> When trying to implement this requirement for QThread, we've run into a
> snag:
> with glibc's pthread implementation on Linux, pthread_exit() as well as all
> POSIX asynchronous cancellations happen by way of a forced stack unwinding.
> This means the obvious solution to implement the requirement from the
> standard
> fails:
>
> try {
> thr->run();
> } catch (...) {
> std::terminate();
> }
>
> That catch (...) block is run by the forced stack unwinding started with
> _Unwind_ForcedUnwind.
>
>
> What does std::current_exception() return here?
$1 = {_M_exception_object = 0x0}
This suggests a solution:
try {
thr->run();
} catch (...) {
if (std::current_exception())
std::terminate();
throw;
}
This code allows a thread to exit cleanly if the run() function above did
pthread_exit(0).
Is this what would be recommended?
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
More information about the cxx-abi-dev
mailing list