Debug "QThread destroyed while thread is still running"

This commit is contained in:
Mat Sutcliffe
2022-10-10 20:47:49 +01:00
parent 39b6305e2e
commit 2efdd6f05e

View File

@@ -103,7 +103,17 @@ namespace BlackMisc
this->moveToThread(workerThread->thread()); // move worker back to the thread which constructed it, so there is no race on deletion
// must not access the worker beyond this point, as it now lives in the owner's thread and could be deleted at any moment
workerThread->deleteLater();
QMetaObject::invokeMethod(workerThread, [workerThread]
{
// quit and wait is redundant as the CRegularThread dtor will do that anyway, but put here for debugging
workerThread->quit();
const bool ok = workerThread->wait(5000);
const QString as = QStringLiteral("Worker thread '%2' refuses to stop after worker finished").arg(workerThread->objectName());
const QByteArray asBA = as.toLatin1();
BLACK_AUDIT_X(ok, Q_FUNC_INFO, asBA);
workerThread->deleteLater();
});
}
CWorkerBase::CWorkerBase()
@@ -282,6 +292,16 @@ namespace BlackMisc
this->moveToThread(m_owner->thread()); // move worker back to the thread which constructed it, so there is no race on deletion
// must not access the worker beyond this point, as it now lives in the owner's thread and could be deleted at any moment
workerThread->deleteLater();
QMetaObject::invokeMethod(workerThread, [workerThread]
{
// quit and wait is redundant as the CRegularThread dtor will do that anyway, but put here for debugging
workerThread->quit();
const bool ok = workerThread->wait(5000);
const QString as = QStringLiteral("Worker thread '%2' refuses to stop after worker finished").arg(workerThread->objectName());
const QByteArray asBA = as.toLatin1();
BLACK_AUDIT_X(ok, Q_FUNC_INFO, asBA);
workerThread->deleteLater();
});
}
} // ns