summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/src/threads.qdoc
diff options
context:
space:
mode:
authorSze Howe Koh <szehowe.koh@gmail.com>2013-09-08 16:48:04 +0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-14 02:58:12 +0200
commit5852ddb110e63cc9d2271431a7776978c2249877 (patch)
tree0d12d10461b20aca6de22a7923b769d55aa65fe4 /src/corelib/doc/src/threads.qdoc
parentcddd16c2d564148f4d97dac894a054de1728641a (diff)
Doc: Move multithreading guidelines to the overview page
It's helpful to see how to choose among different solutions, right after seeing short descriptions of all the solutions. - Some minor rewording was done during the move - The example about polling ports in a new thread was removed because there are better ways to do that without threads. Change-Id: I2cb571a4dbf9be93fb0ec88c60fb7406996c345b Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/doc/src/threads.qdoc')
-rw-r--r--src/corelib/doc/src/threads.qdoc56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/corelib/doc/src/threads.qdoc b/src/corelib/doc/src/threads.qdoc
index 3d11c736cf..79bd7a62a3 100644
--- a/src/corelib/doc/src/threads.qdoc
+++ b/src/corelib/doc/src/threads.qdoc
@@ -178,7 +178,14 @@
See the \l{Qt Concurrent} module documentation for details on the individual functions.
- \section1 Comparison of Solutions
+ \section1 Choosing an Appropriate Approach
+
+ As demonstrated above, Qt provides different solutions for developing threaded
+ applications. The right solution for a given application depends on the purpose
+ of the new thread and the thread's lifetime. Below is a comparison of Qt's
+ threading technologies, followed by recommended solutions for some example use cases.
+
+ \section2 Comparison of Solutions
\table
\header
@@ -228,6 +235,53 @@
\li Yes
\endtable
\sup{\e{*Except QtConcurrent::run(), which is like QRunnable}}
+
+
+ \section2 Example Use Cases
+
+ \table
+ \header
+ \li Lifetime of thread
+ \li Operation
+ \li Solution
+ \row
+ \li One call
+ \li Run a linear function within another thread, optionally with progress
+ updates during the run.
+ \li Qt provides different solutions:
+ \list
+ \li Place the function in a reimplementation of QThread::run() and
+ start the QThread. Emit signals to update progress. OR
+ \li Place the function in a reimplementation of QRunnable::run() and
+ add the QRunnable to a QThreadPool. Write to a \l{Synchronizing
+ Threads}{thread-safe variable} to update progress. OR
+ \li Run the function using QtConcurrent::run(). Write to a \l{Synchronizing
+ Threads}{thread-safe variable} to update progress.
+ \endlist
+ \row
+ \li One call
+ \li Perform an operation on all items of a container, using all available
+ cores. For example, producing thumbnails from a list of images.
+ \li Use Qt Concurrent's \l{QtConcurrent::}{filter()} function to select
+ container elements, and the \l{QtConcurrent::}{map()} function to apply
+ an operation to each element. To fold the output into a single result,
+ use \l{QtConcurrent::}{filterReduced()} and \l{QtConcurrent::}{mapReduced()}
+ instead.
+ \row
+ \li Permanent
+ \li Have an object living in another thread that can perform different
+ tasks upon request and/or can receive new data to work with.
+ \li Subclass a QObject to create a worker. Instantiate this worker object
+ and a QThread. Move the worker to the new thread. Send commands or
+ data to the worker object over queued signal-slot connections.
+ \row
+ \li Permanent
+ \li Repeatedly perform an expensive operation in another thread, where the
+ thread does not need to receive any signals or events.
+ \li Write the infinite loop directly within a reimplementation of QThread::run().
+ Start the thread without an event loop. Let the thread emit signals to
+ send data back to the GUI thread.
+ \endtable
*/
/*!