Thanks ill give it a go 😊

-----Original Message-----
From: Interest <interest-boun...@qt-project.org> On Behalf Of Thiago Macieira
Sent: Tuesday, August 17, 2021 13:14
To: interest@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@qt-project.org
https://lists.qt-project.org/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to