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
This commit is contained in:
Maksim Derbasov 2023-08-09 17:26:46 +09:00 committed by GitHub
parent 037bed5b3c
commit 8166bfc7b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -24,6 +24,8 @@
#include "importproject.h"
#include "suppressions.h"
#include <atomic>
#include <QList>
#include <QObject>
#include <QString>
@ -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<State> mState{Ready};
ThreadResult &mResult;
/**

View File

@ -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,