ThreadPool icon indicating copy to clipboard operation
ThreadPool copied to clipboard

Should ThreadPool provide a function which waits until all thread finish?

Open morefreeze opened this issue 6 years ago • 5 comments

Dear developer: I want to add shutdown function that waits until all worker finish. Because I found ThreadPool will deconstructing directly if process exit. I think user have right to choose terminate ThreadPool or wait for finishing.

Are you agree with me? If you do I can submit a PR. Have a good day!

morefreeze avatar Aug 10 '18 09:08 morefreeze

I have forked and modified this ThreadPool for use in log4cplus where I have implemented this functionality. See https://github.com/log4cplus/Threadpool.

I believe the aim of this repository is to provide a starting point thread pool rather than a complete implementation with many features.

wilx avatar Aug 10 '18 10:08 wilx

That's great! Learning new things from you.

On Fri, Aug 10, 2018 at 6:09 PM Václav Haisman [email protected] wrote:

I have forked and modified this ThreadPool for use in log4cplus where I have implemented this functionality. See https://github.com/log4cplus/Threadpool.

I believe the aim of this repository is to provide a starting point thread pool rather than a complete implementation with many features.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/progschj/ThreadPool/issues/59#issuecomment-412039788, or mute the thread https://github.com/notifications/unsubscribe-auth/ABaKcT5QBOs2fNM4r6pxXtRbT77yMNLwks5uPVvugaJpZM4V36Ve .

-- One of my most productive days was throwing away 1000 lines of code.

morefreeze avatar Aug 10 '18 10:08 morefreeze

I have forked and modified this ThreadPool for use in log4cplus where I have implemented this functionality. See https://github.com/log4cplus/Threadpool.

I believe the aim of this repository is to provide a starting point thread pool rather than a complete implementation with many features.

excellent job, man. I get the help in 2022 from you in 2018, maybe that is the charm of Internet.

hunter2009pf avatar Oct 12 '22 12:10 hunter2009pf

@wilx Could you please add some bit example or comment to understand the usage of pool.wait_until_empty(); pool.wait_until_nothing_in_flight();

sjdhanasekaran avatar Apr 24 '23 10:04 sjdhanasekaran

When you are destroying the object that owns the thread pool, you have to wait until the queue is empty and there are no threads running with the queued items. E.g.,

https://github.com/log4cplus/log4cplus/blob/4cd02bb7c513f9ae098ab34bccdaa57340e4531c/src/global-init.cxx#L388-L393

wilx avatar Apr 24 '23 11:04 wilx