Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to terminate thread in a more graceful manner, and avoid deadlock (race?).
[graphlib.git] / DrawingWindow.cpp
index 1ab14ee..d1ef81b 100644 (file)
@@ -669,7 +669,7 @@ bool DrawingWindow::waitMousePress(int &x, int &y, int &button,
     if (terminateThread) {
         pressed = false;
     } else {
-        pressed = mouseCondition.wait(&mouseMutex, time);
+        pressed = mouseCondition.wait(&mouseMutex, time) && !terminateThread;
         if (pressed) {
             x = mousePos.x();
             y = mousePos.y();
@@ -751,7 +751,7 @@ void DrawingWindow::usleep(unsigned long usecs)
 void DrawingWindow::closeEvent(QCloseEvent *ev)
 {
     timer.stop();
-    thread->terminate();
+    thread->exit();
     syncMutex.lock();
     mouseMutex.lock();
     terminateThread = true;     // this flag is needed for the case
@@ -765,7 +765,10 @@ void DrawingWindow::closeEvent(QCloseEvent *ev)
     mouseMutex.unlock();
     syncMutex.unlock();
     QWidget::closeEvent(ev);
-    thread->wait();
+    if (!thread->wait(250)) {
+        thread->terminate();
+        thread->wait();
+    }
 }
 
 /*!