diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-09-22 12:18:44 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-09-22 12:26:27 (GMT) |
commit | b93947f5a25b3cc021518b944dc96b892f672bd3 (patch) | |
tree | 8307c61613e4357778b2ef891b573d6a69fe03c5 | |
parent | 4035ec3e9ed5ef904dd6f22adaf5e9deb24e9455 (diff) | |
download | Qt-b93947f5a25b3cc021518b944dc96b892f672bd3.zip Qt-b93947f5a25b3cc021518b944dc96b892f672bd3.tar.gz Qt-b93947f5a25b3cc021518b944dc96b892f672bd3.tar.bz2 |
QThread: make sure start works even if called after exit
Regression in 4.7.0 introduced by 13ca61fcfdc53a6a06a
Reviewed-by: brad
Task-number: QTBUG-13810
-rw-r--r-- | src/corelib/thread/qthread_unix.cpp | 2 | ||||
-rw-r--r-- | src/corelib/thread/qthread_win.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qthread/tst_qthread.cpp | 41 |
3 files changed, 45 insertions, 0 deletions
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 2824e15..a7601b6 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -514,6 +514,8 @@ void QThread::start(Priority priority) d->running = true; d->finished = false; d->terminated = false; + d->returnCode = 0; + d->exited = false; pthread_attr_t attr; pthread_attr_init(&attr); diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 37d5b87..f0cbe8d 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -405,6 +405,8 @@ void QThread::start(Priority priority) d->running = true; d->finished = false; d->terminated = false; + d->exited = false; + d->returnCode = 0; /* NOTE: we create the thread in the suspended state, set the diff --git a/tests/auto/qthread/tst_qthread.cpp b/tests/auto/qthread/tst_qthread.cpp index 7a5b053..843749a 100644 --- a/tests/auto/qthread/tst_qthread.cpp +++ b/tests/auto/qthread/tst_qthread.cpp @@ -49,6 +49,7 @@ #include <qtimer.h> #include <qwaitcondition.h> #include <qdebug.h> +#include <qmetaobject.h> #ifdef Q_OS_UNIX #include <pthread.h> @@ -104,6 +105,8 @@ private slots: void adoptedThreadFinished(); void adoptMultipleThreads(); + void QTBUG13810_exitAndStart(); + void stressTest(); }; @@ -934,6 +937,44 @@ void tst_QThread::stressTest() } } +class Syncronizer : public QObject +{ Q_OBJECT +public slots: + void setProp(int p) { + if(m_prop != p) { + m_prop = p; + emit propChanged(p); + } + } +signals: + void propChanged(int); +public: + Syncronizer() : m_prop(42) {} + int m_prop; +}; + +void tst_QThread::QTBUG13810_exitAndStart() +{ + QThread thread; + thread.exit(555); //should do nothing + + thread.start(); + + //test that the thread is running by executing queued connected signal there + Syncronizer sync1; + sync1.moveToThread(&thread); + Syncronizer sync2; + sync2.moveToThread(&thread); + connect(&sync2, SIGNAL(propChanged(int)), &sync1, SLOT(setProp(int)), Qt::QueuedConnection); + connect(&sync1, SIGNAL(propChanged(int)), &thread, SLOT(quit()), Qt::QueuedConnection); + QMetaObject::invokeMethod(&sync2, "setProp", Qt::QueuedConnection , Q_ARG(int, 89)); + QTest::qWait(50); + while(!thread.wait(10)) + QTest::qWait(10); + QCOMPARE(sync2.m_prop, 89); + QCOMPARE(sync1.m_prop, 89); +} + QTEST_MAIN(tst_QThread) #include "tst_qthread.moc" |