From 76a1c060ac76a9249febdb32e71fcddaf7fb2414 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Wed, 23 Mar 2022 09:30:23 +0100 Subject: Always cancel unfinished QPromises on destruction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the QPromise is being destroyed, we should signal the associated futures to stop waiting. No matter in which state the promise is, if it's not finished, we should always cancel to avoid infinite waits. This is also what docs state: "The promise implicitly transitions to a canceled state on destruction unless finish() is called beforehand by the user." Fixes: QTBUG-101284 Pick-to: 6.3 6.2 Change-Id: I65ebfefe03b79b41afacda78a4f49938c54d8b37 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Andrei Golubev Reviewed-by: Edward Welbourne Reviewed-by: MÃ¥rten Nordheim --- tests/auto/corelib/thread/qpromise/tst_qpromise.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/auto/corelib/thread/qpromise/tst_qpromise.cpp') diff --git a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp index 52f4daa24a..5c20287e89 100644 --- a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp +++ b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp @@ -64,6 +64,7 @@ private slots: void cancelWhenDestroyed(); #endif void cancelWhenReassigned(); + void cancelWhenDestroyedWithoutStarting(); void finishWhenSwapped(); void cancelWhenMoved(); void waitUntilResumed(); @@ -505,6 +506,19 @@ void tst_QPromise::cancelWhenReassigned() #endif } +void tst_QPromise::cancelWhenDestroyedWithoutStarting() +{ + QFuture future; + { + QPromise promise; + future = promise.future(); + } + future.waitForFinished(); + QVERIFY(!future.isStarted()); + QVERIFY(future.isCanceled()); + QVERIFY(future.isFinished()); +} + void tst_QPromise::finishWhenSwapped() { #if !QT_CONFIG(cxx11_future) -- cgit v1.2.3