summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-12-23 16:23:45 +0100
committerIvan Solovev <ivan.solovev@qt.io>2023-01-09 10:03:48 +0100
commita8261e327d6316d944cfcc312a1b2e71bd4e5d27 (patch)
treecd8e49af5e838e27ad9227311009741091c96d1c /tests/auto/corelib/thread
parent8a30b22930d3a3d15fba97ff7aec7f812721869e (diff)
QPromise: improve documentation snippet
The multi-thread snippet in the documentation, when copied as is, could actually crash because of the race condition between the main thread and the thread that generate results for the promise. This is fixed by explicitly calling QPromise::start(). Actually, the underlying snippet already has this call, it just was not included in the documentation. This patch modifies the documentation snippet to include calls to both QPromise::start() and QPromise::finish(). Fixes: QTBUG-109230 Pick-to: 6.5 6.4 6.2 Change-Id: Ic25f31a6b3b16ba6bc06a0b199289c8c5d50bab6 Reviewed-by: Sona Kurazyan <kurazyan.sona@gmail.com>
Diffstat (limited to 'tests/auto/corelib/thread')
-rw-r--r--tests/auto/corelib/thread/qpromise/snippet_qpromise.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/tests/auto/corelib/thread/qpromise/snippet_qpromise.cpp b/tests/auto/corelib/thread/qpromise/snippet_qpromise.cpp
index e87ba82309..a1c7da280e 100644
--- a/tests/auto/corelib/thread/qpromise/snippet_qpromise.cpp
+++ b/tests/auto/corelib/thread/qpromise/snippet_qpromise.cpp
@@ -53,9 +53,9 @@ void snippet_QPromise::multithreadExample()
QFuture<int> future = sharedPromise->future();
// ...
-//! [multithread_init]
sharedPromise->start();
+//! [multithread_init]
//! [multithread_main]
// here, QPromise is shared between threads via a smart pointer
@@ -88,7 +88,9 @@ void snippet_QPromise::multithreadExample()
for (auto& t : threads)
t->wait();
+//! [multithread_cleanup]
sharedPromise->finish();
+//! [multithread_cleanup]
#endif
}