From 8166bfc7b823242c87b17cb62fac015e5720fa3c Mon Sep 17 00:00:00 2001 From: Maksim Derbasov Date: Wed, 9 Aug 2023 17:26:46 +0900 Subject: [PATCH] Do not crash on GUI shutdown (#5288) Seems current code for worker threads termination is too brutal which leads to crash on termination: ``` QThread::start: Thread termination error: No such process Segmentation fault (core dumped) ``` Seems better to use `quit()` and `wait()`, like in an example: https://doc.qt.io/qt-6/qthread.html#details tested: Ubuntu Linux 20 --- gui/checkthread.h | 6 ++++-- gui/threadhandler.cpp | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/gui/checkthread.h b/gui/checkthread.h index 9a1fea3e6..d74ec2514 100644 --- a/gui/checkthread.h +++ b/gui/checkthread.h @@ -24,6 +24,8 @@ #include "importproject.h" #include "suppressions.h" +#include + #include #include #include @@ -118,9 +120,9 @@ protected: }; /** - * @brief Thread's current execution state. + * @brief Thread's current execution state. Can be changed from outside */ - State mState = Ready; + std::atomic mState{Ready}; ThreadResult &mResult; /** diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 43faf2aea..6e99afe04 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -148,7 +148,10 @@ void ThreadHandler::setThreadCount(const int count) void ThreadHandler::removeThreads() { for (CheckThread* thread : mThreads) { - thread->terminate(); + if (thread->isRunning()) { + thread->terminate(); + thread->wait(); + } disconnect(thread, &CheckThread::done, this, &ThreadHandler::threadDone); disconnect(thread, &CheckThread::fileChecked,