PDA

View Full Version : Waiting for multiple threads



Bebee
18th November 2008, 11:39
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:

Thread1 prod1;
Thread2 prod2;
.;
Thread3 prod3;
Thread cons;

prod1.start();
prod2.start();
.;
prod3.start();
prod1.wait();
prod2.wait();
.;
prod3.wait();
cons.start();
cons.wait();
Each of the threads is an instance of different object. I guess that QWaitCondition is useless since several producers are used.
Thk’s Vojta.

wysota
18th November 2008, 17:21
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.