From 28984cd5ba63c557b88377f996a90b9665f37745 Mon Sep 17 00:00:00 2001 From: Sze Howe Koh Date: Tue, 25 Feb 2014 09:17:08 +0100 Subject: 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 This is a cherry-pick from 3b45dfe6e6ff6c0626b in qtbase.git Change-Id: If3b65f3da4e1ca414c7175c4e22bcdef38f45442 Reviewed-by: Sze Howe Koh Reviewed-by: Jerome Pasion --- doc/src/tutorials/threads.qdoc | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'doc') diff --git a/doc/src/tutorials/threads.qdoc b/doc/src/tutorials/threads.qdoc index 055290842d..ad66b9f061 100644 --- a/doc/src/tutorials/threads.qdoc +++ b/doc/src/tutorials/threads.qdoc @@ -277,19 +277,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. @@ -326,18 +316,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 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()} -- cgit v1.2.3