Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Qt 4.8.x QThread Showstopper

$
0
0
I developed a multithreaded app, using QThread, in Qt 4.6.2. The app works fine also in Qt 4.7.4. However, in both Qt 4.8.3 and Qt 4.8.4, my app fails due to changes in qthread_unix.cpp [the same problem occurs within qthread_win.cpp]. Specifically, in Qt 4.8.x the emit finished() signal is issued before the running and finished attributes are set. In Qt 4.6.2 and Qt 4.7.4, the running and finished attributes are correctly set before the emit finished() signal is sent. My app uses several QThreads in an array, with a common slot for handling the finished() signal. Thus, my slot needs to inspect the finished attributes of threads to determine which one raised the signal [the signal doesn’t indicate by itself which thread finished]. Here’s a snippet from the Qt 4.7.4 qthread_unix.cpp from line 355:     d->priority = QThread::InheritPriority;     d->running = false;     d->finished = true;     if (d->terminated)         emit thr->terminated();     d->terminated = false;     emit thr->finished(); Note that the running and finished attributes are set before emitting finished(). This sequence enables my slot handling the finish() signal reliably to determine which thread signalled finish(). This same (correct) sequence is in qthread_win.cpp also. On the other hand, in Qt 4.8.4, the snippet from qthread_unix.cpp reads (from line 359):     emit thr->finished();     QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);     QThreadStorageData::finish((void **)data);     locker.relock();     d->terminated = false;     QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher;     if (eventDispatcher) {         d->data->eventDispatcher = 0;         locker.unlock();         eventDispatcher->closingDown();         delete eventDispatcher;         locker.relock();     }       d->thread_id = 0;     d->running = false;     d->finished = true; Note that the running and finished attributes are set AFTER the finished() signal is sent. This prevents my slot handling the finished() signal from reliably determining, by examining the finished attribute of all threads, which thread just finished. Again, qthread_win.cpp exhibits the same issue. This issue is also present in Qt 4.8.x MinGW.

Viewing all articles
Browse latest Browse all 18427

Trending Articles