From 959fd59bd5bb72dde5db4975443c69045ea2fe53 Mon Sep 17 00:00:00 2001 From: Matthew Vogt Date: Wed, 23 May 2012 15:52:31 +1000 Subject: [PATCH] Ensure that main thread processes worker data events 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 Reviewed-by: Yunqiao Yin --- src/qml/qml/qquickworkerscript.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/qml/qml/qquickworkerscript.cpp b/src/qml/qml/qquickworkerscript.cpp index 7e0a0f3..0343312 100644 --- a/src/qml/qml/qquickworkerscript.cpp +++ b/src/qml/qml/qquickworkerscript.cpp @@ -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(); } -- 2.7.4