Hi I'm currently trying to create a thread pool for a io_service object.
I also found an example of how to do this (see there, example 1f: http://www.gamedev.net/blog/950/entry-2249317-a-guide-to-getting-started-with-boostasio?pg=2 )
That example also works (of course) however I would rather try to keep the io_service non-global (which it is in the example). So now I have thought about trying to pass the io_service as an argument to the worker thread and therefore keep it "internal".
boost::thread_group doesn't seem to have support for passing arguments though (yet) so I tried to do it with boost::bind
The result code looks something like this:
void workerThread(io_service service)
{
service.run();
}
void initListeners() //this function gets called in the main function
{
io_service io_service;
//we give the io_service something to work here
boost::thread_group worker_threads;
for(int i = 0; i < 4; ++i)
worker_threads.create_thread(boost::bind(workerThread, io_service));
worker_threads.join_all();
}
However when I try to compile this code he gives me the error
error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member declared in class 'boost::noncopyable_::noncopyable'
This diagnostic occurred in the compiler generated function 'boost::asio::io_service::io_service(const boost::asio::io_service &)'
Does this mean I can't pass an io_service object as an argument at all?
If yes then how can I do this thread pool without having the io_service as a global object?
If no then how would the solution for this problem look like with the above code?