Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to (properly) check if ALL started QThread workers finished their tasks
Forum Updated to NodeBB v4.3 + New Features

How to (properly) check if ALL started QThread workers finished their tasks

Scheduled Pinned Locked Moved Solved General and Desktop
qthreadqthreadpoolmovetothreadworkerthread
5 Posts 3 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by
    #1

    I haven't used multithreading (especially QThreads) that often before and I'm wondering how to check if all started worker QThreads are finished() to continue processing the result from my threads in my GUI class.
    I came across QThreadPool::waitForDone() but as far as I understand, it only works with QRunnable?!
    In plain C++ I would just do something like std::thread->join() on all threads.

    Currently I'm using the classic "worker QObject + moveToThread()" approach with multiple workers /QThreads and I don't want to change it for now.

    Thanks in advance :)


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAIR, the equivalent would be wait however it's blocking and likely not what you want.

      You should rather have a counter that you decrement each time a task is done and then do the rest once it reached zero.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Pl45m4P 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        AFAIR, the equivalent would be wait however it's blocking and likely not what you want.

        You should rather have a counter that you decrement each time a task is done and then do the rest once it reached zero.

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #3

        @SGaist said in How to (properly) check if ALL started QThread workers finished their tasks:

        AFAIR, the equivalent would be wait however it's blocking and likely not what you want.

        No :)

        You should rather have a counter that you decrement each time a task is done and then do the rest once it reached zero.

        A counter as member variable in my MainWindow class will work?!

        So I connect finished() to an additional slot which will decrease my member?


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That would be one way yes, if you spawn all your threads there.

          Depending on what you want to do you might want to consider modeling the execution using a state machine.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • O Offline
            O Offline
            ollarch
            wrote on last edited by
            #5

            Hi,

            You can connect the "finished()" signal to a slot and there check if all threads are not running. I assume that you have a list of threads.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved