Philipp Henkel wrote:
Hi,
I'm the author of a boost based thread pool lib (http://threadpool.sf.net) mentioned before in the "boost::thread queries" thread and I would like to give you some insight in the lib's future. As there's strong request for further features I plan to extend the pool step by step.
this sounds great! I use your lib in one of my current projects and it proved to be useful and stable. I have a question regarding changing the number of threads: sometimes I need to explicitly kill all worker threads. therefor I set the number of threads to zero using pool::resize(0) and wait for all active tasks to finish. this works as long as there are at least as many task in queue as there are threads to be killed. it does not work for empty queues. consider the following (pseudo) code: // create an empty pool with 5 worker threads pool p(5); // try to kill all worker threads (the queue is still empty) p.resize(0); since we did not add a task all worker threads are still running (waiting for some work to do). they will be killed as soon as we schedule some tasks. well, this isn't to bad at the first look. but in my special case each running worker thread acquires some kind of resource and I need to be able to create and remove worker on demand without any delay. I worked around the problem by scheduling a 'dummy-task' for each thread in case of an empty queue. but I am not convinced this is a good way of doing this ... do you think there is a better way? sascha