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:
Code:
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.
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.