[Development] Using platform-native APIs for terminating QThreads

Thiago Macieira thiago.macieira at intel.com
Sat Sep 3 09:03:21 CEST 2016


Em sexta-feira, 2 de setembro de 2016, às 23:45:26 CEST, Marc Mutz escreveu:
> On Friday 02 September 2016 22:35:59 Thiago Macieira wrote:
> > However, the documentation from the ABI says that forced unwinds cannot be
> > stopped, so you can't swallow the exception even if you wanted to. Are you
> > sure that the application crashes when you pthread_exit() when
> > QThreadPrivate::start() is noexcept?
> 
> Can't swallow doesn't mean can't catch. You can catch it, but you can't not
> rethrow. But if you call std::terminate(), the rethrow will never be
> reached.

But that doesn't do what we want. We want to rethrow the __forced_unwind 
exception so that it terminates the thread, but not the entire application.

But anyway, what I asked didn't work. Test app:

#include <pthread.h>

void do_exit() noexcept
{
    pthread_exit(nullptr);
}

int dummy;
void *thread_function(void *)
{
    do_exit();
    return &dummy;
}

int main()
{
    pthread_t thr;
    void *retval;
    pthread_create(&thr, nullptr, thread_function, nullptr);
    pthread_join(thr, &retval);
    return retval == nullptr ? 0 : 1;
}

Crash backtrace:
#0  0x00007ffff6fa9975 in raise () from /lib64/libc.so.6
#1  0x00007ffff6faad8a in abort () from /lib64/libc.so.6
#2  0x00007ffff78ca6bd in __gnu_cxx::__verbose_terminate_handler() () from /
usr/lib64/libstdc++.so.6
#3  0x00007ffff78c8696 in ?? () from /usr/lib64/libstdc++.so.6
#4  0x00007ffff78c86e1 in std::terminate() () from /usr/lib64/libstdc++.so.6
#5  0x00007ffff78c8314 in __gxx_personality_v0 () from /usr/lib64/libstdc+
+.so.6
#6  0x00007ffff73275a9 in ?? () from /lib64/libgcc_s.so.1
#7  0x00007ffff7327904 in _Unwind_ForcedUnwind () from /lib64/libgcc_s.so.1
#8  0x00007ffff7bcacb0 in __pthread_unwind () from /lib64/libpthread.so.0
#9  0x00007ffff7bc3595 in pthread_exit () from /lib64/libpthread.so.0
#10 0x0000000000400794 in do_exit() ()
#11 0x00000000004007a5 in thread_function(void*) ()
#12 0x00007ffff7bc2474 in start_thread () from /lib64/libpthread.so.0
#13 0x00007ffff705d3ed in clone () from /lib64/libc.so.6

I'll post to cxxabi and ask that __forced_unwind be made public API.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list