[Qt-interest] QMutex deadlock without using QMutex

Andre Somers andre at familiesomers.nl
Tue Apr 27 17:42:50 CEST 2010


Hi Sean,

On 27-4-2010 16:50, Sean Harmer wrote:
> On Tuesday 27 April 2010 15:31:33 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.
>>      
> You say from that *part* of the application. Are you sure that the error
> message is coming from this part of your application?
>    
Yes. It is in the middle of a huge calculation that has been running for 
a bit on all four worker threads for a while already. All worker threads 
have processed about 500 packages of work before one after the other 
they run into this deadlock. At that point, the application itself still 
works, but the calculation stops and CPU usage goes down from 100% to 
almost 0. And no, using 100% CPU is not bad ;-)
>> Still, I get this error in my output:
>> QMutex::lock: Deadlock detected in thread<some number>
>>      
> Can you reproduce this in a small example that uses just your data processing
> threads?
>    
Not so easy, no, I think.
> Have a grep through the Qt source to find where that message is printed and
> then set a break point there to see where in your code it is being triggered
> from.
>    
Good idea. Done that, and posted the result in reply to the message from 
Gabriel.
>> What could this mean? Are there other causes conceivable for this
>> happening? Is there behind-the-scenes locking/unlocking of mutexes that
>> Qt is doing when performing signalling between threads?
>>      
> I am not sure but I do not think so.
It turns out that it does, actually. Not that weird when you think about it.

>   However, I think that Qt does use worker
> threads in a couple of other places such as QFileSystemWatcher (on some
> platforms only I think) and in QFileSystemModel. Not sure if these make use of
> mutexes internally or not though.
>    
I'm not using any of these, at least not here (I am using file dialogs 
elsewhere, and those in turn may use the above classes).

André





More information about the Qt-interest-old mailing list