summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@edeltech.ch>2018-05-24 23:03:39 +0200
committerSamuel Gaist <samuel.gaist@edeltech.ch>2018-06-03 20:26:47 +0000
commitabe3373489c5afb35917b319d1d83b8505ba1f52 (patch)
tree5dedb38ad5998e3f8ec39084ca220b27bf63b91c /src/corelib/thread
parent73a991cbc3e2a20bc9f90fb793b0ae4d93ac9997 (diff)
Doc: Add information about QThread own methods thread affinity
This patch improves the documentation regarding the thread affinity of QThread's own methods. It's not always clear for people new to threading that a QThread object lives in the old thread were it was instantiated and that calling the methods of said objects will also happen there. Change-Id: I3599851ebc97a33602ca6499da254a08aec59b2b Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qthread.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index 7d908fd4e7..23606411ff 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -219,14 +219,17 @@ QThreadPrivate::~QThreadPrivate()
It is important to remember that a QThread instance \l{QObject#Thread
Affinity}{lives in} the old thread that instantiated it, not in the
new thread that calls run(). This means that all of QThread's queued
- slots will execute in the old thread. Thus, a developer who wishes to
- invoke slots in the new thread must use the worker-object approach; new
- slots should not be implemented directly into a subclassed QThread.
-
- When subclassing QThread, keep in mind that the constructor executes in
- the old thread while run() executes in the new thread. If a member
- variable is accessed from both functions, then the variable is accessed
- from two different threads. Check that it is safe to do so.
+ slots and \l {QMetaObject::invokeMethod()}{invoked methods} will execute
+ in the old thread. Thus, a developer who wishes to invoke slots in the
+ new thread must use the worker-object approach; new slots should not be
+ implemented directly into a subclassed QThread.
+
+ Unlike queued slots or invoked methods, methods called directly on the
+ QThread object will execute in the thread that calls the method. When
+ subclassing QThread, keep in mind that the constructor executes in the
+ old thread while run() executes in the new thread. If a member variable
+ is accessed from both functions, then the variable is accessed from two
+ different threads. Check that it is safe to do so.
\note Care must be taken when interacting with objects across different
threads. See \l{Synchronizing Threads} for details.