diff options
| author | Vladimir Belyavsky <[email protected]> | 2025-11-09 09:08:37 +0300 |
|---|---|---|
| committer | Thiago Macieira <[email protected]> | 2025-11-14 03:37:45 +0000 |
| commit | 220e59668e876b4b85126d26fcec84fa9b802c0e (patch) | |
| tree | d60fe4eb63f75f73efd7af497c9e8a9923b89aaa | |
| parent | 37d502557722b17b848432345edd7731d0bad507 (diff) | |
See 5677b70eee2e923eea8e5150500ac745d8d54974 for details why we need
such specific exception handling for Glibc. In short, on Glibc,
pthread_cancel and pthread_exit are implemented by throwing a special
kind of exception that can be caught, but must always be rethrown. That
exception is then used to activate the cancellation clean-up handlers.
But for libc++ on Apple platforms we can simply wrap it as noexcept
to guarantee that std::terminate() will be called in case of any
unhandled exception.
Task-number: QTBUG-141803
Pick-to: 6.10 6.8
Change-Id: Iaa88d3a8091425206ee2735e835ae74fd087e9e0
Reviewed-by: Thiago Macieira <[email protected]>
| -rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 1ba73b49b45..bdab8dfb028 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -358,26 +358,28 @@ static void setCurrentThreadName(const char *name) #endif namespace { +#if defined(__GLIBCXX__) && !defined(QT_NO_EXCEPTIONS) template <typename T> void terminate_on_exception(T &&t) { -#ifndef QT_NO_EXCEPTIONS try { -#endif std::forward<T>(t)(); -#ifndef QT_NO_EXCEPTIONS -#ifdef __GLIBCXX__ - // POSIX thread cancellation under glibc is implemented by throwing an exception - // of this type. Do what libstdc++ is doing and handle it specially in order not to - // abort the application if user's code calls a cancellation function. } catch (abi::__forced_unwind &) { + // POSIX thread cancellation under glibc is implemented by throwing an exception + // of this type. Do what libstdc++ is doing and handle it specially in order not to + // abort the application if user's code calls a cancellation function. throw; -#endif // __GLIBCXX__ } catch (...) { std::terminate(); } -#endif // QT_NO_EXCEPTIONS } +#else +template <typename T> +void terminate_on_exception(T &&t) noexcept +{ + std::forward<T>(t)(); +} +#endif // defined(__GLIBCXX__) && !defined(QT_NO_EXCEPTIONS) } // unnamed namespace void *QThreadPrivate::start(void *arg) |
