On 10/04/2012 03:21 PM, Sujan Dasmahapatra wrote: > I am not able to run my threads concurrently please help. > How can I run 21 threads concurrently and get the job done by 8 cpus > what I have in my machine. > > I am doing like this > [code] > > std::vector<QFuture<void> > Threads; > QFuture<void> Th; > > for(int z=0; z<21; z++) > { > Th = QtConcurrent::run(this,&UnrstParser,z); > Thraeds.push_back(Th); > } > for(int th=0; th<Threads.size(); th++) > { > if(Threads[th].isRunning()) > Threads[th].waitForFinished(); > Threads[th].cancel(); > } > Threads.clear(); > [/code] > > With this first few threads are probably running but not all the > threads. As it's supposed to generate some files by each thread which is > not being generated. Please help.
My guess is that not all the threads will have started yet when you hit the loop, and so when you do if (Threads[th].isRunning()) it returns false and then you do Threads[th].cancel() which probably means it will never run. Just do Threads[th].waitForFinished() in the loop and nothing else. -- Samuel _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest