Results 1 to 13 of 13

Thread: How to loop multithreaded job

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to loop multithreaded job

    Hi all!

    My base classes are:
    Qt Code:
    1. class Manager: public QThread
    2. class Worker: public QThread
    To copy to clipboard, switch view to plain text mode 

    Manager starts 4 (independed) workers and "listens" for their signals (and counts finished workers). Manager restarts workers several times.
    It also emits final results to GUI thread.
    This is all working flawless.

    Now, i want to loop whole job (manager's job) in Tester thread.

    Qt Code:
    1. void Tester::run(void)
    2. {
    3. for (int iParam1 = 0; iParam1 < parameter1.size(); iParam1++)
    4. {
    5. for (int iParam2 = 0; iParam2 < parameter2.size(); iParam2++)
    6. {
    7. double tmpValueSum = 0.0;
    8. for (int iRun = 0; iRun < numberOfRuns; iRun++)
    9. {
    10. manager->parameter1 = parameter1[iParam1];
    11. manager->parameter2 = parameter2[iParam2];
    12.  
    13. manager->run();
    14. manager->wait(); // This is a problem
    15. }
    16. results[iParam1][iParam2] = tmpValueSum / double(numberOfRuns);
    17. }
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    I miss something in the way I understood wait function. I tried exit(), quit() and exec() in Manager...
    What modifications should be implemented to make this possible?

    In base case, i only have manager->run(); and there is no need for waiting... Manager emits some output and final results to GUI thread.

    Thanks!

    EDIT: I found this example
    .
    As I see it, the only important difference is that my thread raises other threads and have few connections...
    Last edited by stefan; 20th December 2012 at 16:23.

Similar Threads

  1. Replies: 4
    Last Post: 6th August 2011, 01:40
  2. multithreaded QImageReader
    By dcole in forum Qt Programming
    Replies: 7
    Last Post: 23rd June 2011, 22:16
  3. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 16:31
  4. Multithreaded Server
    By niol1000 in forum Newbie
    Replies: 1
    Last Post: 24th February 2010, 17:33
  5. Multithreaded spend CPU 100%
    By wisconxing in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2008, 07:03

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
  •  
Qt is a trademark of The Qt Company.