Thread pool Implementation using Boost::thread class
I want to implement thread pool using boost::thread class.
I am able to create the threads using below line.
where consumer_1 is thread and consume is the function bound to it.
Above statement starts the thread as soon as it gets executed.
Now I just want to create the thread and do the binding run time.
I have not yet discovered the boost method to delay this binding.
Can anyone help on this?
The binding can't be done later. For principal reasons—a thread of execution has to be executing something.
What you need to do is create a function, that will take jobs, represented as boost::function, from a queue and execute them. Than run this function in one or more threads.
I am not sure there is a thread-safe queue, but you can always use a regular std::deque with boost::condition_variable for waking up the threads and boost::mutex for locking the deque.