I have an object that once created executes many tasks in the background, but should block untill /all/ posted tasks are finished. I.e.:
struct run_many{
boost::asio::io_service m_io_service;
boost::thread_group m_threads;
boost::asio::signal_set m_signals;
void evaluate(std::string work, int i){ /*...*/ }
void run_tasks(int tasks, std::string work){
{
boost::asio::io_service::work w(m_io_service); //
for(int i=0;i<tasks;i++)
m_io_service.post(boost::bind(&run_many::evaluate, this, work, i));
}
//m_io_service.run(); // blocks forever
m_io_service.stop(); // seems to cut off queued jobs
m_threads.join_all(); // works only after m_io_service.stop()
}
run_many(int n_workers)
{
m_threads.create_thread(boost::bind(&boost::asio::io_service::run,m_io_service);
}
};
So I am stuck... it seems that I can either wait forever or cut off the queue after the currently running job in each thread. There must be something I'm missing in the docs?