Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-08-07 07:44:57


Hello,

I would like to ask if it makes sence to introduce a data structure in boost::threads library,
which implements a threads pool.

Sometimes a system design can look like:

Create a maximum of N threads and execute these threads with different tasks. If there more than N
threads running then the threads_pool::get_thread(...) operation should block until one of threads
gets ready.

It is also possible to implement threads_pool::get_thread to use a policy which can block if the N
is reached or return N+1 created thread.

What I miss now in the threading library is the ability to reuse the thread. I think thread
creation in the OS is an expensive task. If one has created thread, there should be a possiblity
to reuse it. I understand it is possible to pass a function to the thread which executes tasks
from the queue and therefore reuses threads, but this involves user implementation of such a
function each time this programming pattern needs to be fullfilled.

Would not it be a better idea to define a thread pool interface which has a synchronized queue
(priority or not, should be customizeable) of tasks and pool of threads which are able to execute
these tasks (boost::function0<void>) instances? I don't think I am the first person who comes up
with this question... Would be really nice to hear your input on this issues or at least some
links pointing to explanation, why this should not be done.

With Kind Regards,

Ovanes Markarian


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net