summaryrefslogtreecommitdiffstats
path: root/tests/auto/qthread
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@kde.org>2011-11-03 14:11:34 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-19 05:42:49 +0100
commit82566b811c2d0714f4a2bd23ef040b6e8a5f18bd (patch)
tree410083b8524a00df6e5c8be7e247f40089eedf89 /tests/auto/qthread
parent3fe6a74576f8c0c4e04343e0db94364f76fea407 (diff)
QThread::isFinished should return true from finished()
and isRunning() should return false. This restore the Qt 4.7 behaviour In Qt 4.7, the finished() was called with the thread's intenal mutex locked. Which mean that: - Call to isRunning or isFinished called from a slot connected to finish within the thread would deadlock. (Hence no compatibility to keep here) - Call to isRunning or isFinished from a slot connected with QueuedConnection in another thread would lock the mutex until the destructors are finished. and then return as if the thread have finished. Change-Id: I963eccae8f7634aff90cc4bbab6ca886a78e35eb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry-picked from qtbase commit ec5e59b73c20a7dc6aec96c829f1e53c3fa58c07) Task-number: QTBUG-30251 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/qthread')
-rw-r--r--tests/auto/qthread/tst_qthread.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/qthread/tst_qthread.cpp b/tests/auto/qthread/tst_qthread.cpp
index c56d302546..ee9ac309af 100644
--- a/tests/auto/qthread/tst_qthread.cpp
+++ b/tests/auto/qthread/tst_qthread.cpp
@@ -117,6 +117,7 @@ private slots:
void destroyFinishRace();
void startFinishRace();
void startAndQuitCustomEventLoop();
+ void isRunningInFinished();
void stressTest();
#ifdef Q_OS_SYMBIAN
@@ -1418,5 +1419,39 @@ void tst_QThread::threadNameTest()
}
#endif // Q_OS_SYMBIAN
+class FinishedTestObject : public QObject {
+ Q_OBJECT
+public:
+ FinishedTestObject() : ok(false) {}
+ bool ok;
+public slots:
+ void slotFinished() {
+ QThread *t = qobject_cast<QThread *>(sender());
+ ok = t && t->isFinished() && !t->isRunning();
+ }
+};
+
+void tst_QThread::isRunningInFinished()
+{
+ for (int i = 0; i < 15; i++) {
+ QThread thread;
+ thread.start();
+ FinishedTestObject localObject;
+ FinishedTestObject inThreadObject;
+ localObject.setObjectName("...");
+ inThreadObject.moveToThread(&thread);
+ connect(&thread, SIGNAL(finished()), &localObject, SLOT(slotFinished()));
+ connect(&thread, SIGNAL(finished()), &inThreadObject, SLOT(slotFinished()));
+ QEventLoop loop;
+ connect(&thread, SIGNAL(finished()), &loop, SLOT(quit()));
+ QMetaObject::invokeMethod(&thread, "quit", Qt::QueuedConnection);
+ loop.exec();
+ QVERIFY(!thread.isRunning());
+ QVERIFY(thread.isFinished());
+ QVERIFY(localObject.ok);
+ QVERIFY(inThreadObject.ok);
+ }
+}
+
QTEST_MAIN(tst_QThread)
#include "tst_qthread.moc"