diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 22f0489c770..de18bcb0969 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -345,6 +345,13 @@ void QThreadPrivate::finish(void *arg) QThread *thr = reinterpret_cast(arg); QThreadPrivate *d = thr->d_func(); + // Disable cancellation; we're already in the finishing touches of this + // thread, and we don't want cleanup to be disturbed by + // abi::__forced_unwind being thrown from all kinds of functions. +#ifdef PTHREAD_CANCEL_DISABLE + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, nullptr); +#endif + QMutexLocker locker(&d->mutex); d->isInFinish = true; diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index 9582343a012..65cf97cdf34 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -1951,7 +1951,6 @@ void tst_QThread::terminateSelfStressTest() struct Thread : QThread { void run() override { terminate(); - while (true) sleep(1ns); // QTBUG-127008 } };