boost::asio::io_service ioService;
boost::thread_group threadpool;
boost::barrier barrier(5);
boost::asio::io_service::work work(ioService);
threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioService)); //Thread 1
threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioService)); //Thread 2
threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioService)); //Thread 3 threadpool.create_thread(boost::bind(&boost::asio::io_service::run, &ioService)); //Thread 4
while (true)
{
{
boost::lock_guard<boost::recursive_mutex> lock(mutex_);
map::iterator it = m_map.begin();
while (it != m_map.end())
{
ioService.post(boost::bind(&ProcessFun, this, it));
++it;
}
ioService.run(); <-- main thread is stuck here..
}
}
I want to have the ability to know that all of the tasks that were assigned to the thread pool have been done, only after to assign tasks again to the thread pool.
As long as the threads are processing the tasks I don't want to release the lock. Is there any way I can make sure all of the assigned tasks are done? And only then to proceed?