[Qt-interest] QMutex deadlock without using QMutex

Andre Somers andre at familiesomers.nl
Tue Apr 27 17:32:03 CEST 2010


On 27-4-2010 16:56, Gabriel M. Beddingfield wrote:
> On Tue, 27 Apr 2010, Andre Somers wrote:
>
>> I am running into a weird problem.
>> For running calculations on a large dataset, I split up the work over a
>> number of threads. I use signals and slots to communicate between the
>> worker threads and a coordinator thread, and also between that
>> coordinator thread and the rest of the application. I do not use any
>> explicit thread synchronisation methods like QMutex in that part of the
>> application.
>
> Shooting from the hip:  this sounds like a mistake.  You have a 
> multi-threaded, message-passing application, but you're ignoring the 
> fundamentals of multi-threaded, message-passing programming.
Please enlighten me: which fundamentals are you refering to, exactly?
It was my understanding that by using a message passing system (such as 
Qt's Queued connections), the message passing system itself takes care 
of all synchronization needed. Note that my worker threads are only 
reading from shared resources, never writing to them. The workers keep a 
private storage with results, which are merged after all worker threads 
are done.
>> Still, I get this error in my output:
>> QMutex::lock: Deadlock detected in thread <some number>
>>
>> What could this mean? Are there other causes conceivable for this
>
> Can't tell what's happening without a backtrace.  Having debugging 
> symbols for Qt libs is probably also necc.
After setting a breakpoint at the two places where this error can be 
triggered (qmutex.cpp lines 162 and 200; Qt 4.6.2) I managed to get a trace:

0    QMutex::lock    qmutex.cpp    201    0x00e10f4e
1    QMutexLocker::relock    qmutex.h    120    0x00f5c564
2    QMutexLocker    qmutex.h    102    0x00f5c604
3    QCoreApplicationPrivate::sendPostedEvents    
qcoreapplication.cpp    1271    0x00efe127
4    qt_internal_proc    qeventdispatcher_win.cpp    482    0x00f1f73f
5    USER32!DefDlgProcW    C:\WINDOWS\syswow64\user32.dll    0    
0x7d9472d8
6    ??        0    0x003f06a8
7    ??        0    0x00000401
8    ??        0    0x00000000

Following the item at line 3, I notice that Qt is indeed using a mutex 
for the message passing. So, it seems we are dealing with Qt's mutex, 
not mine.

Question is then: why does Qt's message system get into a deadlock?

André




More information about the Qt-interest-old mailing list