I'm trying to use boost::asio::io_service as a thread pool executor.
Here's my attempt:
----
using std::vector;
using boost::bind;
using boost::thread;
using boost::shared_ptr;
using boost::asio::io_service;
class executor
{
public:
executor(size_t n): service_(n), work_(service_)
{
for (size_t i = 0; i < n; i++)
{
shared_ptr<thread> worker(new thread(bind(&io_service::run,
&service_)));
pool_.push_back(worker);
}
}
~executor()
{
service_.stop();
for (auto i = pool_.begin(); i != pool_.end(); ++i)
{
(*i)->join();
}
}
template<typename F> void submit(F task)
{
service_.post(task);
}
private:
io_service service_;
io_service::work work_;
vector