Commit 9493d476 authored by Eike Ziller's avatar Eike Ziller
Browse files

mapReduce/runAsync: Fix behavior of waitForFinished

When a QFutureInterface is constructed, it is in "NoState",
but waitForFinished only blocks if it is in "Running" state.
So we need to reportStarted actually before the thread is started
(so we report it before leaving the mapReduce/runAsync method)

Change-Id: I1cdf0d627c5a6c26797b04fd0d331cddb01d50af
Reviewed-by: default avatarNikolai Kosjar <>
Reviewed-by: default avatarOrgad Shaneh <>
parent 67153b22
......@@ -512,7 +512,6 @@ void blockingMapReduce(QFutureInterface<ReduceResult> futureInterface, const Con
const ReduceFunction &reduce, const CleanUpFunction &cleanup)
auto state = init(futureInterface);
mapReduceLoop(futureInterface, container, map, state, reduce);
cleanup(futureInterface, state);
if (futureInterface.isPaused())
......@@ -523,7 +522,6 @@ void blockingMapReduce(QFutureInterface<ReduceResult> futureInterface, const Con
template <typename ResultType, typename Function, typename... Args>
void runAsyncImpl(QFutureInterface<ResultType> futureInterface, const Function &function, const Args&... args)
function(futureInterface, args...);
if (futureInterface.isPaused())
......@@ -540,6 +538,7 @@ QFuture<ReduceResult> mapReduce(std::reference_wrapper<Container> containerWrapp
auto fi = QFutureInterface<ReduceResult>();
QFuture<ReduceResult> future = fi.future();
std::thread(Internal::blockingMapReduce<Container, InitFunction, MapFunction, ReduceResult, ReduceFunction, CleanUpFunction>,
fi, containerWrapper, init, map, reduce, cleanup).detach();
return future;
......@@ -561,6 +560,7 @@ template <typename ResultType, typename Function, typename... Args>
QFuture<ResultType> runAsync(Function &&function, Args&&... args)
QFutureInterface<ResultType> futureInterface;
std::thread(Internal::runAsyncImpl<ResultType,Function,Args...>, futureInterface,
std::forward<Function>(function), std::forward<Args>(args)...).detach();
return futureInterface.future();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment