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 Change-Id: Ic25f31a6b3b16ba6bc06a0b199289c8c5d50bab6 Reviewed-by: Sona Kurazyan <kurazyan.sona@gmail.com> (cherry picked from commit a8261e327d6316d944cfcc312a1b2e71bd4e5d27) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
181688d57d
commit
3acc8fa9d3
@ -38,6 +38,8 @@
|
||||
\snippet snippet_qpromise.cpp multithread_init
|
||||
\codeline
|
||||
\snippet snippet_qpromise.cpp multithread_main
|
||||
\codeline
|
||||
\snippet snippet_qpromise.cpp multithread_cleanup
|
||||
|
||||
\sa QFuture
|
||||
*/
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user