Ensure that main thread processes worker data events
authorMatthew Vogt <matthew.vogt@nokia.com>
Wed, 23 May 2012 05:52:31 +0000 (15:52 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 24 May 2012 00:36:05 +0000 (02:36 +0200)
If the main thread goes into a wait for the worker thread before
the worker thread posts the event that triggers the main thread to
process generated data, deadlock results.

Change-Id: I3788acef73e82aa96f2b86bcb48933d01ae86841
Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
src/qml/qml/qquickworkerscript.cpp

index 7e0a0f3..0343312 100644 (file)
@@ -485,8 +485,13 @@ QQuickWorkerScriptEngine::~QQuickWorkerScriptEngine()
     //We have to force to cleanup the main thread's event queue here
     //to make sure the main GUI release all pending locks/wait conditions which
     //some worker script/agent are waiting for (QQuickListModelWorkerAgent::sync() for example).
-    QCoreApplication::processEvents();
-    wait();
+    while (!isFinished()) {
+        // We can't simply wait here, because the worker thread will not terminate
+        // until the main thread processes the last data event it generates
+        QCoreApplication::processEvents();
+        yieldCurrentThread();
+    }
+
     d->deleteLater();
 }