Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.2.4
-
None
Description
Found this while investigating QTBUG-103922:
Sample code:
for (int i = 0; i < 1000; ++i) { QThread thread; thread.start(); thread.terminate(); thread.wait(); }
Sometimes this causes a hung at least on Windows - probably due to some internal race condition.
Pay attention that terminate() sometimes may have no any effect here, it just returns early because termination is not yet enabled in QThreadPrivate::start().
see src/corelib/thread/qthread_win.cpp:
unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(void *arg) noexcept { ... QThread::setTerminationEnabled(false); ... QThread::setTerminationEnabled(true); ... }
void QThread::terminate() { ... if (!d->terminationEnabled) { d->terminatePending = true; return; // <---- } ... }
Attachments
Issue Links
- relates to
-
QTBUG-103922 Calling QThread::terminate() in destructor causes double object destruction
- Closed