[Interest] how to run 21 threads concurrently

Jan Kundrát jkt at flaska.net
Thu Oct 4 23:45:58 CEST 2012


On 10/04/12 23:35, Sujan Dasmahapatra wrote:
> for(int th=0; th<Threads.size(); th++)
> {
> if(Threads[th].isRunning())
> Threads[th].waitForFinished();
> Threads[th].cancel();
> }
> Threads.clear();
> This loop is correct. If threads is running wait, then cancel it. braces
> are proper Sascha.

The code you pasted is equivalent to the following:

for(int th=0; th<Threads.size(); th++) {
   if(Threads[th].isRunning()) {
     Threads[th].waitForFinished();
   }
   Threads[th].cancel();
}
Threads.clear();

Have you considered a situation where a QConcurrent job has not started 
yet at the time the loop comes around to check if it's alive? Because 
your code will unconditionally kill all such tasks; they will *not* run.

(As a side note, calling a QFuture a "thread" is not very clear. Threads 
and futures are two different things which do have something in common, 
but they are different. In my opinion, calling a list of futures 
"threads" is wrong.)

Cheers,
Jan

-- 
Trojita, a fast e-mail client -- http://trojita.flaska.net/



More information about the Interest mailing list