Skip to content

Commit

Permalink
Attempts to prevent hanging process
Browse files Browse the repository at this point in the history
Now won't wait forever for background thread.
Still, the mystical error with COM4 persists: hang detected, but process not stopped
  • Loading branch information
NIA committed Nov 19, 2014
1 parent 8119c34 commit 3bf43e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace {

const int TIME_SYNC_PERIOD_SECS = 60; // sync time every minute
const int NEW_FILE_PERIOD_SECS = 60*60; // reset file every hour
const int MAX_WAIT = 5000; // Wait background threads no more than 5 secs

void initPortChooser(QComboBox * chooser, QString initialValue) {
chooser->addItem(TEST_PROTOCOL);
Expand Down Expand Up @@ -574,14 +575,12 @@ bool MainWindow::askForClosing() {
}

void MainWindow::closeEvent(QCloseEvent *e) {
if (workerStarted) {
if (false == askForClosing()) {
e->ignore();
} else {
e->accept();
}
if (workerStarted && (false == askForClosing()) ) {
e->ignore();
} else {
e->accept();
// Calls Worker::finish and FileWriter::closeIfOpened
emit finishing();
}
}

Expand All @@ -593,7 +592,16 @@ MainWindow::~MainWindow()

threadFileWriter->quit();
threadWorker->quit();
threadFileWriter->wait();
if (false == threadWorker->wait(MAX_WAIT)) {
Logger::error(tr("Worker thread hangs"));
} else {
delete worker;
}
if (false == threadFileWriter->wait(MAX_WAIT)) {
Logger::error(tr("FileWriter thread hangs"));
} else {
delete fileWriter;
}

perfPlotting.reportResults();
FileWriter::perfReporter.reportResults();
Expand All @@ -605,7 +613,5 @@ MainWindow::~MainWindow()
TestProtocol::perfReporter.reportResults();
perfTotal.flushDebug();

delete worker;
delete fileWriter;
delete ui;
}
4 changes: 3 additions & 1 deletion src/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,16 @@ void Worker::finalizeProtocol(Protocol * protocol) {
}

void Worker::finish() {
if (started) {
stop();
}
finalizeProtocol(protocolADC_);
if (protocolADC_ != protocolGPS_) {
finalizeProtocol(protocolGPS_);
}
autostart = false;
prepared = false;
started = false;
emit startedOrStopped(false);
emit finished();
}

Expand Down

0 comments on commit 3bf43e7

Please sign in to comment.