[Qt-interest] QMutex deadlock without using QMutex
Andre Somers
andre at familiesomers.nl
Tue Apr 27 18:38:44 CEST 2010
Hi Gabriel,
Thanks for your insights.
On 27-4-2010 18:10, Gabriel M. Beddingfield wrote:
> i.e. you're relying Qt's Queued Connections for thread synchronization
> primatives. These, of course, are using Mutexes and Sempahores and
> Atomic ops.
That's why I said I'm not using them explicitly. Meaning that perhaps Qt
uses them behind the scenes anyway, as it turns out it is.
>
>> 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?
>
> Not sure. Deadlocks are hard to solve.
>
> In case you don't know, it usually happens when this is effectively
> executed:
>
> QMutex mut;
>
> void some_func()
> {
> mut.lock();
> //...
> mut.lock(); // <== deadlock
> }
>
> The second lock() will wait for the mutex to unlock, which will never
> happen.
>
> Perhaps switch from Qt::QueuedConnection to
> Qt::BlockingQueuedConnection (or the reverse). You might get lucky.
Ehh? Swithing to a blocking connection would defeat the purpose of using
threading in the first place I think? If the work manager thread has to
wait for each worker thread to finish it's work before being able to
handle anything else, I would effectively have a single threaded
application as the other threads do nothing but wait for work, I
think... Or do I totally misunderstand the documentation here? If I try
it, I get up to about 25% CPU usage on my quad core system. That's
single threaded performance.
André
More information about the Qt-interest-old
mailing list