progschj / ThreadPool

A simple C++11 Thread Pool implementation
zlib License
7.64k stars 2.21k forks source link

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

Open morefreeze opened 5 years ago

morefreeze commented 5 years ago

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!

wilx commented 5 years ago

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.

morefreeze commented 5 years ago

That's great! Learning new things from you.

On Fri, Aug 10, 2018 at 6:09 PM Václav Haisman notifications@github.com 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.

hunter2009pf commented 1 year ago

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.

sjdhanasekaran commented 1 year ago

@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();

wilx commented 1 year ago

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