Results 1 to 2 of 2

Thread: Waiting for multiple threads

  1. #1
    Join Date
    Nov 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Waiting for multiple threads

    Hi,
    I’ve got maybe simple question but I didn’t find appropriate answer jet. Can someone help me if there is an elegant way how to wake-up one thread (“cons”) when several threads (“prod”) are finished. This code doesn’t work well:
    Qt Code:
    1. Thread1 prod1;
    2. Thread2 prod2;
    3. .;
    4. Thread3 prod3;
    5. Thread cons;
    6.  
    7. prod1.start();
    8. prod2.start();
    9. .;
    10. prod3.start();
    11. prod1.wait();
    12. prod2.wait();
    13. .;
    14. prod3.wait();
    15. cons.start();
    16. cons.wait();
    To copy to clipboard, switch view to plain text mode 
    Each of the threads is an instance of different object. I guess that QWaitCondition is useless since several producers are used.
    Thk’s Vojta.

  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: Waiting for multiple threads

    QWaitCondition is the way to go, but you have to use it properly. The consumer has to go back to sleep when it is awaken if it detects there are still some producers running.

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.