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.

boost::thread Consumer_1(consume); 

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.

You might want to look at Boost.Asio too. See also here.

Need Your Help

How does deleteObject: work in coreData?

iphone ios core-data

I just took the plunge and rewrote my App on top of CoreData (previously I was using my own internal save format).

How do I get the start and end character indices of an HTML element?

javascript html

Trying to figure out how to get the range of characters affected by an element in an overall HTML document using JavaScript. I only need webkit compatible code.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.