Im developing an application in Qt which, at some point, process a bunch of videos. It works fine but it had only a 40-60% of the cpu usage during the process phase so i tried to make it multithreaded.
I used QtConcurrent cause his 'high leveness' instead a more traditional thread management, my code is simply:
for(int i = 0; i < totalVideos; i++)
{
QFuture<ResultClass *> futureToken = QtConcurrent::run(this, process, listOfVideos.takeFirst());
QFutureWatcher<ResultClass *>* fw = new QFutureWatcher<ResultClass *>();
connect(fw, SIGNAL(finished()), this, SLOT(manageResult));
fw->setFuture(futureToken);
}
aaaand it works, 100% cpu usage and its around 25-30% faster. But it spawns around 65 new threads (regardless it process 25 or 250 videos) and most of those threads doesn't disappear after the process phase.
My question is: Is this approach right? Is it too raw? Should i control 'manually' the thread creation? Does the QtConcurrent module takes care of all so i should not care of the thread management? Are 85 threads too much? Should i try to kill some of those after the process phase??
Every observation has been done just looking at the Activity monitor.
Thanks in advance.