Results 1 to 5 of 5

Thread: Another QWaitCondition error (destroyed while threads are running)

  1. #1
    Join Date
    Jun 2015
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Another QWaitCondition error (destroyed while threads are running)

    Hello,

    I have seen many people face a similar problem, but none of the answers solves mine. Below is a complete minimal example that reproduces the problem.

    Qt Code:
    1. #include <QtCore/QtConcurrentMap>
    2. #include <vector>
    3.  
    4. void work ( double & d )
    5. {
    6. d = 1.;
    7. return;
    8. }
    9.  
    10. void main ( int argc, char ** argv )
    11. {
    12. std::vector<double> v(500,0.);
    13. QtConcurrent::blockingMap(v.begin(),v.end(),work);
    14.  
    15. return;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Compiled with Qt 4.8.3 and Visual Studio 2010, the produced executable complains that a QWaitCondition was destroyed while threads were still waiting. What am I doing wrong? Should I upgrade Qt to fix this issue? Is there any workaround in case I can't upgrade right away?

    Thank you for the time and support.

    Yohann

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Another QWaitCondition error (destroyed while threads are running)

    You could try calling waitForDone() on the global QThreadPool instance before returning from main()

    Cheers,
    _

  3. #3
    Join Date
    Jun 2015
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Another QWaitCondition error (destroyed while threads are running)

    Hi,

    Your suggestion works. Thank you.
    Should I consider it a workaround (later versions of Qt don't/won't require this) or is it just the right thing to do?

    Thank you

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Another QWaitCondition error (destroyed while threads are running)

    You could also try instantiating a QCoreApplication before running anything on the global thread pool.
    Its cleanup code might be doing something similar.

    My guess is that the waitForDone() of the threadpool destructor comes too late in your case because the global instance is destroyed so close after being used.

    The explicit call to waitForDone() just ensures that the pool's worker threads get stopped and removed before the application gets into that state of partial deconstruction it enters when main() ends.

    Cheers,
    _

  5. #5
    Join Date
    Jun 2015
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Another QWaitCondition error (destroyed while threads are running)

    Ok, thank you again.

Similar Threads

  1. Replies: 1
    Last Post: 10th December 2014, 08:59
  2. QWaitCondition: Destroyed while threads are still waiting
    By TimShnaider in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2012, 02:07
  3. Replies: 1
    Last Post: 27th January 2011, 15:02
  4. Replies: 0
    Last Post: 15th April 2010, 13:44
  5. Replies: 0
    Last Post: 8th June 2009, 08:12

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.