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 <j...@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@qt-project.org > > http://lists.qt-project.org/mailman/listinfo/interest _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest