Results 1 to 9 of 9

Thread: QtConcurrent::run() and exit()

  1. #1
    Join Date
    May 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QtConcurrent::run() and exit()

    Long story short: when I call exit() from a process started from QtConcurrent::run() it enters an infinite loop here:
    Qt Code:
    1. 0 pthread_cond_wait pthread_cond_wait.S 162 0x00007ffff609459c
    2. 1 wait qwaitcondition_unix.cpp 87 0x00007ffff6a27a7b
    3. 2 QWaitCondition::wait qwaitcondition_unix.cpp 159 0x00007ffff6a27a7b
    4. 3 QThreadPoolPrivate::waitForDone qthreadpool.cpp 295 0x00007ffff6a1c808
    5. 4 QThreadPool::~QThreadPool qthreadpool.cpp 428 0x00007ffff6a1cfff
    6. 5 QGlobalStaticDeleter<QThreadPool>::~QGlobalStaticDeleter qglobal.h 1796 0x00007ffff6a1d695
    7. 6 __run_exit_handlers exit.c 78 0x00007ffff55ad045
    8. 7 exit exit.c 100 0x00007ffff55ad095
    9. 8 fsElement::fsElement fselement.cpp 41 0x000000000040b266
    10. 9 fsElement::populateDirList fselement.cpp 65 0x000000000040b70b
    11. 10 fsElement::findFilesAndDirs fselement.cpp 120 0x000000000040be77
    12. 11 fsElement::findFilesAndDirs fselement.cpp 122 0x000000000040be9c
    13. 12 fsElement::findFilesAndDirs fselement.cpp 122 0x000000000040be9c
    14. 13 fsElement::findFilesAndDirs fselement.cpp 122 0x000000000040be9c
    15. 14 fsElement::findFilesAndDirs fselement.cpp 122 0x000000000040be9c
    16. 15 fsElement::findFilesAndDirs fselement.cpp 122 0x000000000040be9c
    17. 16 fsElement::findFilesAndDirs fselement.cpp 122 0x000000000040be9c
    18. 17 fsElement::findFilesAndDirs fselement.cpp 122 0x000000000040be9c
    19. 18 fsElement::findFilesAndDirs fselement.cpp 122 0x000000000040be9c
    20. 19 QtConcurrent::VoidStoredMemberFunctionPointerCall0<void, fsElement>::runFunctor qtconcurrentstoredfunctioncall.h 216 0x000000000040adc4
    21. 20 QtConcurrent::RunFunctionTask<void>::run qtconcurrentrunbase.h 120 0x000000000040a396
    22. 21 QThreadPoolThread::run qthreadpool.cpp 106 0x00007ffff6a1ca4f
    23. 22 QThreadPrivate::start qthread_unix.cpp 248 0x00007ffff6a26a25
    24. 23 start_thread pthread_create.c 301 0x00007ffff608fc1a
    25. 24 clone clone.S 115 0x00007ffff5649a9d
    To copy to clipboard, switch view to plain text mode 
    So I guess I shouldn't use exit() in this fashion. Is there some other way to exit a thread in this situation?

    Bonus, longer question: I just want a way to perform some heavy i/o work and still keep the GUI up to date and responsive (I'm writing a file searching app as an exercise). Doing it in a seperate thread worked quite well, but I'd also like to have the ability to pause and cancel the work. Is threading the best way to do it? What should I do to do it right? QThread? QRunnable? Or is QtConcurrent the best way?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtConcurrent::run() and exit()

    [wiki]Keeping the GUI Responsive[/wiki]
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    pmitas (24th September 2010)

  4. #3
    Join Date
    May 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtConcurrent::run() and exit()

    Great article, thanks. But what about my first question? Is there no way to exit a process in a similar way?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtConcurrent::run() and exit()

    You want to exit the whole process or just the thread?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    May 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtConcurrent::run() and exit()

    Oops. Yeah, whenever I said "process" I meant "thread" :P

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtConcurrent::run() and exit()

    Just return from your concurrent function then. You cannot abort a running concurrent function from outside - it could render your application in an unpredictable state. If you want to be able to abort an inprogress operation, you have to use some other approach (i.e. the "solving the problem step by step" one from the article - either in an external thread or in the main thread).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    May 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtConcurrent::run() and exit()

    Quote Originally Posted by wysota View Post
    Just return from your concurrent function then.
    It's a multi-branch recursive function, returning to the bottom wouldn't be easy.
    Quote Originally Posted by wysota View Post
    You cannot abort a running concurrent function from outside - it could render your application in an unpredictable state.
    I'm not - I'm trying to abort it from the inside at a safe point in response to a flag being set.

    To sum things up, I just want to be able to call a function from a thread that would make the thread just drop everything and stop messing with my data structures Can I do that?

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtConcurrent::run() and exit()

    You can throw exceptions from your function and catch them at the upper-most level and then return from the thread function.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #9
    Join Date
    May 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtConcurrent::run() and exit()

    Good suggestion. Thanks again.

Similar Threads

  1. QtConcurrent, i need advice
    By SABROG in forum Qt Programming
    Replies: 10
    Last Post: 29th December 2009, 19:53
  2. Why is QtConcurrent so slow?
    By ArlexBee-871RBO in forum Qt Programming
    Replies: 10
    Last Post: 29th December 2009, 10:37
  3. qtconcurrent
    By knishaq in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2009, 08:41
  4. QtConcurrent Performance
    By tomf in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2008, 15:41
  5. QtConcurrent
    By Brandybuck in forum An Introduction to QThreads
    Replies: 2
    Last Post: 9th May 2008, 14:10

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.