PDA

View Full Version : Qt::BlockingQueuedConnection blocks worker thread indefinitely if I close application



moldovan_catalin
1st July 2010, 09:53
Hi,

I have an application on N900 that has two threads, the UI thread and a worker thread. In the UI thread I connect a signal from the worker thread with a slot from the UI using Qt::BlockingQueuedConnection (I need this because I cannot create QPixmap in other thread than UI thread) and it works great until I close the application, when sometimes the worker thread doesn't die. I found the problem to be related to this blocking connection, it seems that when the UI dies the semaphore or mutex that is used to block the worker thread is not unlocked in the UI thread and worker thread hangs forever.
Does anyone have any suggestion how could I prevent this? (Please don't tell me to stop using Qt::BlockingQueuedConnection, that's not an answer).

Thanks,
Catalin

high_flyer
1st July 2010, 11:58
Does anyone have any suggestion how could I prevent this?
Unlock the mutex in your GUI destructor.
Or, force terminate you work thread in your GUI destructor.

moldovan_catalin
1st July 2010, 14:45
Terminating the worker thread by force is not an accepted solution, regarding the lock, this is exactly what I'm trying to do, release the lock generated by the qt metacall but I believe I don't have access to that. I was thinking that when the UI thread dies it disconnects the connected signals and slots and unlocks any existing locks if there is a blocking connection, but apparently it is not the case, or this could be a bug. I will try to have a look at qt's source code and the generated mocs maybe I can figure this out.

Ambuja
2nd January 2012, 11:57
Hi,

This is a deadlock situation.
Use
QCoreApplication::processEvents(); or
QCoreApplication::sendPostedEvents();
in main GUI thread where the process is blocking (deadlock).