[Interest] QThreadPool wait until all queued threads are finished

Scott Bloom scott at towel42.com
Tue Aug 17 22:27:04 CEST 2021


Thanks ill give it a go 😊

-----Original Message-----
From: Interest <interest-bounces at qt-project.org> On Behalf Of Thiago Macieira
Sent: Tuesday, August 17, 2021 13:14
To: interest at qt-project.org
Subject: Re: [Interest] QThreadPool wait until all queued threads are finished

On Tuesday, 17 August 2021 12:01:25 PDT Scott Bloom wrote:
> std::list< yyy > xxx;
> for( auto && ii : xxx )
> {
>      QThreadPool::globalInstance()->start(
>         [ii]()
>         {
>             doSomething( ii );
>         } );
> }
> 
> Works great for this... However, I want the application waiting until 
> all threads are completed before exiting the tool.
> 
> while (QThreadPool::globalInstance()->activeThreadCount())
> {
>         QThreadPool::globalInstance()->waitForDone(100);
>         qApp->processEvents();
> }

Busy-waiting is never a good idea.

You should use QFuture/QFutureWatcher and react to the latter's signals indicating their jobs are done.

--
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering



_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest


More information about the Interest mailing list