From b93947f5a25b3cc021518b944dc96b892f672bd3 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 22 Sep 2010 14:18:44 +0200 Subject: 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 --- src/corelib/thread/qthread_unix.cpp | 2 ++ src/corelib/thread/qthread_win.cpp | 2 ++ tests/auto/qthread/tst_qthread.cpp | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) 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 #include #include +#include #ifdef Q_OS_UNIX #include @@ -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" -- cgit v0.12