diff options
author | Sze Howe Koh <szehowe.koh@gmail.com> | 2013-10-02 19:55:29 +0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-06 01:07:52 +0200 |
commit | 3b45dfe6e6ff6c0626bc693599725ced639a40aa (patch) | |
tree | bffab2d68aa860f97a0aa8f1366ce6469fd9e51d /src/corelib/doc | |
parent | 4e337ee703e6a40dabbd7b3b6ce41cde4696eaa2 (diff) |
Doc: Discuss the concept of thread affinity in more detail
- Create a section dedicated to this concept, which is fundamental to
signal/event handling
- Move relevant content from the very broad "Thread Basics" page to the
QObject class ref
- Flesh out existing content, including distinguishing signals from
events
- Address the common misconception that "member" = "child"; this has
been encountered several times in the Qt Project forums
Change-Id: I5e7e6c848596e72c0bb623f8442c8389b81ad9ef
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Diffstat (limited to 'src/corelib/doc')
-rw-r--r-- | src/corelib/doc/src/threads-basics.qdoc | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/src/corelib/doc/src/threads-basics.qdoc b/src/corelib/doc/src/threads-basics.qdoc index 5a5c003210..67165b0c24 100644 --- a/src/corelib/doc/src/threads-basics.qdoc +++ b/src/corelib/doc/src/threads-basics.qdoc @@ -185,19 +185,9 @@ \section2 QObject and Threads - A QObject is said to have a \e{thread affinity} or, in other words, that it - lives in a certain thread. This means that, at creation time, QObject saves - a pointer to the current thread. This information becomes relevant when an - event is posted with \l{QCoreApplication::}{postEvent()}. The event will be - put in the corresponding thread's event loop. If the thread where the - QObject lives doesn't have an event loop, the event will never be delivered. - - To start an event loop, \l{QThread::}{exec()} must be called inside - \l{QThread::}{run()}. Thread affinity can be changed using - \l{QObject::}{moveToThread()}. - As mentioned above, developers must always be careful when calling objects' - methods from other threads. Thread affinity does not change this situation. + methods from other threads. \l{QObject#Thread Affinity}{Thread affinity} + does not change this situation. Qt documentation marks several methods as thread-safe. \l{QCoreApplication::}{postEvent()} is a noteworthy example. A thread-safe method may be called from different threads simultaneously. @@ -234,18 +224,6 @@ has terminated. \endlist - A QObject's parent must always be in the same thread. This has a surprising - consequence for objects generated within the \l{QThread::}{run()} method: - - \code - void HelloThread::run() - { - QObject *object1 = new QObject(this); //error, parent must be in the same thread - QObject object2; // OK - QSharedPointer <QObject> object3(new QObject); // OK - } - \endcode - \section2 Using a Mutex to Protect the Integrity of Data A mutex is an object that has \l{QMutex::}{lock()} and \l{QMutex::}{unlock()} |