Im really trying to avoid making my own thread pool. QTHreadPool works great except there is nothing I can do to wait for all queued to finish as well.
Scott From: Jérôme Godbout <jgodb...@dimonoff.com> Sent: Tuesday, August 17, 2021 12:13 To: Scott Bloom <sc...@towel42.com>; interest@qt-project.org Subject: Re: QThreadPool wait until all queued threads are finished You should make a QThreadPool for your need and call the QThreadPool::waitForDone() until all you started is completed. Other side note to help if the above solution is not enough: You could connect to each QThread finished() event and check if all thread has finished. You can check if the QThread is into the QThreadPool.contains(QThread*), but I do not have a solution to have all the QThread* that are running?! It's kind of odd that the QThreadPool doesn't return a QThread when you start one or could at least iterate over them. Jérôme Godbout, B. Ing. Software / Firmware Team Lead O: (418) 682-3636 ext.: 114 C: (581) 777-0050 godbo...@dimonoff.com<mailto:godbo...@dimonoff.com> [signature_2038249735]<https://www.dimonoff.com/> dimonoff.com<https://www.dimonoff.com/> 1015 Avenue Wilfrid-Pelletier, Québec, QC G1W 0C4, 4e étage From: Interest <interest-boun...@qt-project.org<mailto:interest-boun...@qt-project.org>> on behalf of Scott Bloom <sc...@towel42.com<mailto:sc...@towel42.com>> Date: Tuesday, August 17, 2021 at 3:01 PM To: interest@qt-project.org<mailto:interest@qt-project.org> <interest@qt-project.org<mailto:interest@qt-project.org>> Subject: [Interest] QThreadPool wait until all queued threads are finished 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@qt-project.org https://lists.qt-project.org/listinfo/interest