diff --git a/src/corelib/thread/qfuture_impl.h b/src/corelib/thread/qfuture_impl.h index 90abb99d8e8..e4b0ea62894 100644 --- a/src/corelib/thread/qfuture_impl.h +++ b/src/corelib/thread/qfuture_impl.h @@ -1003,20 +1003,21 @@ struct WhenAllContext { using ValueType = typename ResultFutures::value_type; - WhenAllContext(qsizetype size) : count(size) {} + explicit WhenAllContext(qsizetype size) : remaining(size) {} template void checkForCompletion(qsizetype index, T &&future) { futures[index] = std::forward(future); - Q_ASSERT(count > 0); - if (--count <= 0) { + const auto oldRemaining = remaining.fetchAndSubRelaxed(1); + Q_ASSERT(oldRemaining > 0); + if (oldRemaining <= 1) { // that was the last one promise.addResult(futures); promise.finish(); } } - QAtomicInteger count; + QAtomicInteger remaining; QPromise promise; ResultFutures futures; };