Skip to content

Commit

Permalink
Do not crash on GUI shutdown (danmar#5288)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ntfshard authored Aug 9, 2023
1 parent 037bed5 commit 8166bfc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions gui/checkthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "importproject.h"
#include "suppressions.h"

#include <atomic>

#include <QList>
#include <QObject>
#include <QString>
Expand Down Expand Up @@ -118,9 +120,9 @@ class CheckThread : public QThread {
};

/**
* @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;
/**
Expand Down
5 changes: 4 additions & 1 deletion gui/threadhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8166bfc

Please sign in to comment.