From e2e42e3b6f2b317f814aff2858a35a0993c94724 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 31 Jul 2015 00:51:18 +0200 Subject: Fixed possible race conditions. * Ensure we always create the thread-local event loop before any objects in the thread are created, and guarantee the done handler is immediately registered before the query can execute. * Call the callback on emitter destruction in the worker thread, where the eventloop lives, instead of the main thread. With this I can no longer reproduce any deadlocks or memory corruptions that I used to get occasionally before. --- common/clientapi.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common/clientapi.h') diff --git a/common/clientapi.h b/common/clientapi.h index d860305..3ff8472 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -137,6 +137,10 @@ public: //We must guarantee that the emitter is returned before the first result is emitted. //The result provider must be threadsafe. async::run([query, resultSet](){ + QEventLoop eventLoop; + resultSet->onDone([&eventLoop](){ + eventLoop.quit(); + }); // Query all resources and aggregate results KAsync::iterate(getResources(query.resources)) .template each([query, resultSet](const QByteArray &resource, KAsync::Future &future) { @@ -158,10 +162,6 @@ public: //Keep the thread alive until the result is ready if (!resultSet->isDone()) { - QEventLoop eventLoop; - resultSet->onDone([&eventLoop](){ - eventLoop.quit(); - }); eventLoop.exec(); } }); -- cgit v1.2.3