[Qt-interest] End thread when work is done

Andreas Pakulat apaku at gmx.de
Wed Aug 17 21:00:46 CEST 2011


On 17.08.11 18:31:10, Cole, Derek wrote:
> Hello, I have the following:
> 
>         int maxThreads = QThreadPool::globalInstance()->maxThreadCount();
>         int activeThreads =  QThreadPool::globalInstance()->activeThreadCount();
> 
>         for(int j = 0; j < maxThreads - activeThreads; j++ )
>         {
>             QFutureWatcher<bool> *procwatcher;
>             procwatcher = new QFutureWatcher<bool>();
>             procWatchers.push_back(procwatcher);
> 
> 
>             QFuture<bool> procfuture = QtConcurrent::run(this, &EraserBatch::processTile);
>             procFutures.push_back(procfuture);
>             procwatcher->setFuture(procfuture);
>             qDebug()<<"Active threadcount after proc "<<QThreadPool::globalInstance()->activeThreadCount();
> 
>         }
> 
> when "processTile" is finished running for each of these, the method
> returns fine, but when I check the activeThreadCount, it shows all of
> them still running. What can I put to make sure that each thread ends
> when the method to run has ended?

I think you may mis-interpret what activeThreadCount tells you. I can't
see any indication that QThreadPool kills threads when the runnable is
done. A thread started by QThreadPool probably simply waits until more
work is to be done, otherwise the whole pool-idea would not make much
sense.

Andreas




More information about the Qt-interest-old mailing list