PDA

View Full Version : data race between QEventDispatcherGlib::processEvents and QCoreApplication::postEvent



madmax
14th April 2011, 16:10
Dear Qt support/community,

I have plenty of those following errors. I am using QT4.6.2 on Ubuntu linux 10.04, 32 bits.
There are two threads. One is the main/GUI thread and one is a thread_2 doing some calculation. The second thread should call a refresh of the graphical display. For that, the call is as following:

QObject::connect(ringBuffer_InThread_2*, SIGNAL(sendSynchronizeEvent_0(unsigned long, unsigned int)), widget_InMainThread, SLOT(slot_updateDisplay(unsigned long, unsigned int)), Qt::QueuedConnection);

When I check with helgrind (valgrind --tool=helgrind ./myprogram), I got the following error:

Possible data race during write of size 1 at 0x5d19214 by thread #2
==2962== at 0x4E80768: QCoreApplication::postEvent(QObject*, QEvent*, int) (in /usr/lib/libQtCore.so.4.6.2)
==2962== by 0x4E809AB: QCoreApplication::postEvent(QObject*, QEvent*) (in /usr/lib/libQtCore.so.4.6.2)
==2962== by 0x4E92235: ??? (in /usr/lib/libQtCore.so.4.6.2)
==2962== by 0x4E942B0: QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (in /usr/lib/libQtCore.so.4.6.2)
==2962== by 0x8055F58: RingBuffer::sendSynchronizeEvent_0(unsigned long, unsigned int) (in myprogram)
==2962== by 0x80511F9: RingBuffer::checkForSyncronizeSignalEmission(unsig ned long) (in myprogram)
==2962== This conflicts with a previous read of size 1 by thread #1
==2962== at 0x4EACB1F: ??? (in /usr/lib/libQtCore.so.4.6.2)
==2962== by 0x5970AC9: g_main_context_prepare (in /lib/libglib-2.0.so.0.2400.1)
==2962== by 0x5970EE8: ??? (in /lib/libglib-2.0.so.0.2400.1)
==2962== by 0x59714B7: g_main_context_iteration (in /lib/libglib-2.0.so.0.2400.1)
==2962== by 0x4EAC5D4: QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/libQtCore.so.4.6.2)
==2962== by 0x4491134: ??? (in /usr/lib/libQtGui.so.4.6.2)
==2962== by 0x4E7F058: QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/libQtCore.so.4.6.2)
==2962== by 0x4E7F4A9: QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (in /usr/lib/libQtCore.so.4.6.2)

I checked on the mandelbrot example and I got the same error message. I thought postEvent was thread safe. What can I do to avoid this problem ? Using QTimer in the main/GUI thread consume too much CPU for my taste. Thanks in advance for help !