[Interest] how to run 21 threads concurrently

Sujan Dasmahapatra sujan.dasmahapatra at gmail.com
Fri Oct 5 08:53:54 CEST 2012


I have now removed Threads[th].cancel(). Only waitForFinished
 is there as below.

for(int th=0; th<Threads.size(); th++)
{
if(Threads[th].isRunning())
Threads[th].waitForFinished();
}
Eventhough it's not writing the data on the file correctly.
I'll try your code Sascha thanks a lot for so beautiful code snippet.
Thanks Sujan
On Fri, Oct 5, 2012 at 9:41 AM, Harri Pasanen <harri at mpaja.com> wrote:

> Cancelling threads is a no-no in most threading systems I'm familiar
> with, so even reading such code somehow brushes me against feathers...
>
> So out of habit I'd steer away from using cancel even if it were supported.
>
> On 10/05/2012 12:34 AM, Alex Malyushytskyy wrote:
> > Why do you need  Threads[th].cancel();?
> > According to documentation not only "the QFuture returned by
> > QtConcurrent::run() does not support canceling,...", but I do not see
> > any reason you could want to do this.
> >
> > Alex
> >
> >
> >
> > On Thu, Oct 4, 2012 at 6:25 AM, André Somers <andre at familiesomers.nl>
> wrote:
> >> Op 4-10-2012 15:21, Sujan Dasmahapatra schreef:
> >>> 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.
> >>>
> >>>
> >> QtConcurrent will use as many threads as it deems useful, based on the
> >> system you are running on. Unless you have a 21 core system, it is
> >> probably not useful to run 21 threads your your task.
> >> However, QThreadPool has methods to change how many threads are
> >> considdered useful, so you should look into using that class.
> >>
> >> André
> >>
> >> _______________________________________________
> >> Interest mailing list
> >> Interest at qt-project.org
> >> http://lists.qt-project.org/mailman/listinfo/interest
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>



-- 
Regards
Sujan Dasmahapatra
skype: sujan.dasmahapatra
yahoo msn : dasmahapatra.aerodynamics at yahoo.co.in
Mobile no : +966-530184511
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121005/8ef05f29/attachment.html>


More information about the Interest mailing list