[Interest] QThreadPool wait until all queued threads are finished
Federico Ferri
federico.ferri.it at gmail.com
Thu Aug 19 09:51:19 CEST 2021
Why don't you use a QSemaphore?
You instantiate it with n=0 (the default constructor).
Call sem.acquire(xxx.size()) to wait for all tasks to complete, amnd call
sem.release(1) after each task completes.
Best regards,
Federico Ferri
On Tue, Aug 17, 2021 at 9:03 PM Scott Bloom <scott at towel42.com> wrote:
> Here is the problem Im having. I have background task, that is small
> enough to use a lambda on a given string.
>
>
>
> 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();
>
> }
>
>
>
> Should work. Wait 100ms, and continue.
>
>
>
> However, the problem Im having, is activeThreadCount does not take into
> account queued threads.
>
>
>
> Is there a better way? The length of the xxx can be in the millions, and
> is recursive.
>
>
> Scott
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210819/952c501f/attachment.html>
More information about the Interest
mailing list