[Qt-interest] QMutex deadlock without using QMutex

Andre Somers andre at familiesomers.nl
Wed Apr 28 10:02:54 CEST 2010


Hi,

Thanks for your continuing input on this frustrating topic...

On 27-4-2010 21:31, Gabriel M. Beddingfield wrote:
>
>> set to be exact.) They are not called directly as you do above.
>
> Yes.  But you gotta simplify your examples /somewhere/. 
True, but I think this could be a significant difference.
> The point is that while one function is executing... another thread 
> somewhere could steal your worker thread.  This is especially true 
> since you're using asynchronous queues to pass the work.
True, in multithreaded environments, you never really know.
>
>> Would that not mean that just like for the coordinator thread, the 
>> worker
>> threads are not interrupted, as the slot would only be invoked when the
>> worker thread returns to the eventloop? Also: I don't see the 
>> deadlock in
>
> Well, you can always set up a simple test to prove your assumption:
> (...)
> The purpose here is to crash your program if somehow the do_work() 
> method gets called twice at the same time. (Which, if I understand 
> correctly, should not be happening.)  If this test fails... it can 
> help you isolate the cause.
>
> Note that /this/ mutex will not serialize (single-thread) your program 
> like Qt::BlockingQueuedConnection did.
Thanks, a very valuable suggestion! Measuring is much better than 
assuming, especially since somewhere, one of my assumptions must be off 
and triggers this issue. I protected each of the relevant functions with 
a mutex in the manner you suggest, in both the worker threads as well as 
in the worker coordinator. The assertion is not triggered, but the 
deadlock continues to appear.

It gets increasingly difficult to talk about this issue without the 
actual source code. The source is in a public repo, so here are the 
relevant links if somebody cares to take a look at the code:

The issue that is bugging me, is in the classes contained in the 
abstractcalculator.h/.cpp in
http://www.assembla.com/code/srtools/git/nodes/relationcalculator/plugins/basic?rev=6be5e588fbd40ab5f9d73a1f2444734f02dcd66b

The concrete implementation that I am using is in 
sharecountcalculator.h/.cpp in the same directory.

To create the actual worker threads, I use my own worker thread classes 
(QThread based) that allow me to easily create a worker thread from an 
object. In this case, I am using workerthreadonobject.h/.cpp from here:
http://www.assembla.com/code/srtools/git/nodes/common/src?rev=6be5e588fbd40ab5f9d73a1f2444734f02dcd66b


André





More information about the Qt-interest-old mailing list