[Qt-interest] QMutex deadlock without using QMutex

Andre Somers andre at familiesomers.nl
Tue Apr 27 17:13:44 CEST 2010


On 27-4-2010 16:54, Brad Howes wrote:
> On Apr 27, 2010, at 10:31 AM, 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.
>>      
> IOW, you are relying on Qt::QueuedConnection behavior for signal delivery to determine when all worker threads are done?
>    
Yes, as well as for progress information.

Let me try to clarify my setup:
I have my main application with the UI. Then, I have a thread that I 
call a work manager. It coordinates what parts of the work still need to 
be done. This manager creates a set of worker threads to do the actual 
work. It then creates "packages" of work and hands them to the worker 
threads using a queued signal. When the worker thread is done, it 
signals back to the work manager thread (queued again), and waits for a 
new package to be assigned. When the work manager receives the message 
that a worker thread is done processing it's assigned work, as long as 
there is more work to do, it assigns a new package, signals the worker 
thread about that, etc. Only when all the work is done, the results are 
collected from the worker threads and merged.
>> I do not use any explicit thread synchronisation methods like QMutex in that part of the
>> application.
>>      
> Does this mean that you use *implicit* thread sync somewhere, or that you do use QMutex elsewhere in your application?
>    
There is a mutex elsewhere, but that point is already long passed when 
this problem occurs. I have verified that it is not that mutex biting me 
in the ass. I was wondering if Qt uses mutexes in its own code for the 
signal/slot stuff, for instance. That is what i mean when I say "I do 
not use explicit thread synchronization methods": I don't use QMutex or 
the likes, but perhaps Qt is under the hood?

>> Still, I get this error in my output:
>> QMutex::lock: Deadlock detected in thread<some number>
>>      
> Can you set a breakpoint in the source where that statement prints out?
>    
I will try to put a breakpoint in the Qt source.

André




More information about the Qt-interest-old mailing list