Clean learner-thread termination on program exit
This commit is contained in:
parent
1a0d2b9ea7
commit
ab9dcfbd35
@ -24,7 +24,7 @@ void NetLearner::run()
|
||||
timer.start();
|
||||
|
||||
size_t numIterations = 100000;
|
||||
for (size_t iteration = 0; iteration < numIterations; ++iteration)
|
||||
for (size_t iteration = 0; iteration < numIterations && cancel == false; ++iteration)
|
||||
{
|
||||
auto trainingSample = mnistLoader.getRandomSample();
|
||||
|
||||
@ -76,4 +76,11 @@ void NetLearner::run()
|
||||
logString.append(ex.what());
|
||||
emit logMessage(logString);
|
||||
}
|
||||
|
||||
cancel = false;
|
||||
}
|
||||
|
||||
void NetLearner::cancelLearning()
|
||||
{
|
||||
cancel = true;
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ class NetLearner : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
bool cancel = false;
|
||||
|
||||
private:
|
||||
void run() Q_DECL_OVERRIDE;
|
||||
|
||||
@ -15,6 +18,9 @@ signals:
|
||||
void progress(double progress);
|
||||
void currentNetError(double error);
|
||||
void sampleImageLoaded(const QImage &image);
|
||||
|
||||
public slots:
|
||||
void cancelLearning();
|
||||
};
|
||||
|
||||
#endif // NETLEARNER_H
|
||||
|
@ -12,6 +12,12 @@ NeuroUI::NeuroUI(QWidget *parent) :
|
||||
|
||||
NeuroUI::~NeuroUI()
|
||||
{
|
||||
if (m_netLearner != nullptr)
|
||||
{
|
||||
m_netLearner->cancelLearning();
|
||||
m_netLearner->wait();
|
||||
}
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user