Results 1 to 4 of 4

Thread: Qt::BlockingQueuedConnection blocks worker thread indefinitely if I close application

  1. #1
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Qt::BlockingQueuedConnection blocks worker thread indefinitely if I close application

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt::BlockingQueuedConnection blocks worker thread indefinitely if I close applica

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::BlockingQueuedConnection blocks worker thread indefinitely if I close applica

    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.

  4. #4
    Join Date
    Sep 2011
    Posts
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Qt::BlockingQueuedConnection blocks worker thread indefinitely if I close applica

    Hi,

    This is a deadlock situation.
    Use
    Qt Code:
    1. QCoreApplication::processEvents(); or
    2. QCoreApplication::sendPostedEvents();
    To copy to clipboard, switch view to plain text mode 
    in main GUI thread where the process is blocking (deadlock).

Similar Threads

  1. Worker thread
    By doggrant in forum Newbie
    Replies: 4
    Last Post: 3rd November 2009, 15:49
  2. Worker thread problem
    By hkvm in forum Qt Programming
    Replies: 4
    Last Post: 6th September 2009, 20:12
  3. Showing progress bar while worker thread works
    By olidem in forum Qt Programming
    Replies: 6
    Last Post: 27th April 2009, 20:43
  4. Accessing data from a worker thread
    By steg90 in forum Qt Programming
    Replies: 20
    Last Post: 25th May 2007, 10:20
  5. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 22:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.