[Interest] Fwd: how to run 21 threads concurrently

Sujan Dasmahapatra sujan.dasmahapatra at gmail.com
Fri Oct 5 19:53:29 CEST 2012


please check this code snippet. Tell me Sascha if this is
acceptable.....Still it's not writing some data.
[code]

QSemaphore mSemaphore1;

for (int z=0;z<nZ;z++)

{

Th = QtConcurrent::run(

this,&UNRSTParser::ProcessZLayer,&mSemaphore1,z);

 }

mSemaphore1.acquire(nZ);



//ZLayer function is as below

void

UNRSTParser::ProcessZLayer(QSemaphore *sem, int layerID)

{

Q_ASSERT( sem );

//...Everything is done here...writing data to file etc.

sem->release(1);

}
[/code]

On Fri, Oct 5, 2012 at 8:32 PM, Sascha Cunz <sascha-ml at babbelbox.org> wrote:

> Am Freitag, 5. Oktober 2012, 20:20:40 schrieb Sujan Dasmahapatra:
> > This code snippet is nomore hanging. i did some mistake. but it's still
> the
> > same. not writing some data to the file. problem persists. whats still
> > going wrong please help.
> >
> > [code]
> >
> >
> > QSemaphore mSemaphore1;
> >
> > int nZ=1;
> >
> > for (int z=0;z<nZ;z++)
> >
> > {
> >
> > Q_ASSERT( &mSemaphore1 );
> >
> > Th = QtConcurrent::run(
> >
> > this,&UNRSTParser::ProcessZLayer,z);
> >
>
>
> > mSemaphore1.release(1);
>
> This release is at the wrong place. It belong to the _end_ of
> UNRSTParser::ProcessZLayer. That's why I put a helper-class into my
> example.
>
> Doing it here renders the Semaphore useless - Because you want the below
> acquire() to _block until all QFutures are finished_.
>
> > values += (nX*nY);
> >
> > }
> >
> > mSemaphore1.acquire(nZ);
> >
> >
> > [/code]
> >
> > On Fri, Oct 5, 2012 at 2:12 PM, Jan Kundrát <jkt at flaska.net> wrote:
> > > On 10/05/12 00:27, Sascha Cunz wrote:
> > > > But, after all, the above code is a so called busy-loop. It will eat
> up
> > >
> > > 1 core
> > >
> > > > almost completely (At least on most OS-configurations).
> > >
> > > Are you sure that a call to QFuture::waitForFinished() consumes CPU?
> > > That would be highly suspicious. Yes, the call will block and wait
> until
> > > the QFuture succeeds, but that's different from what a busy loop is.
> > >
> > > Using waitForFinished() on each future is easier and more
> > > straightforward than adding semaphores.
> > >
> > > With kind regards,
> > > Jan
> > >
> > > --
> > > Trojita, a fast e-mail client -- http://trojita.flaska.net/
> > > _______________________________________________
> > > 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/8d2ba85c/attachment.html>


More information about the Interest mailing list