Clean learner-thread termination on program exit

This commit is contained in:
mandlm 2015-11-01 12:36:23 +01:00
parent 1a0d2b9ea7
commit ab9dcfbd35
3 changed files with 20 additions and 1 deletions

View File

@ -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;
}

View File

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

View File

@ -12,6 +12,12 @@ NeuroUI::NeuroUI(QWidget *parent) :
NeuroUI::~NeuroUI()
{
if (m_netLearner != nullptr)
{
m_netLearner->cancelLearning();
m_netLearner->wait();
}
delete ui;
}