[Interest] QThreadPool wait until all queued threads are finished

Scott Bloom scott at towel42.com
Tue Aug 17 21:01:25 CEST 2021


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210817/097c0345/attachment.html>


More information about the Interest mailing list