title: How to add new tasks to threadpool only when all the tasks are finished using boost in c++
body: <pre><code>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(&amp;boost::asio::io_service::run, &amp;ioService));  //Thread 1
  threadpool.create_thread(boost::bind(&amp;boost::asio::io_service::run, &amp;ioService));  //Thread 2
  threadpool.create_thread(boost::bind(&amp;boost::asio::io_service::run, &amp;ioService));  //Thread 3 threadpool.create_thread(boost::bind(&amp;boost::asio::io_service::run, &amp;ioService));  //Thread 4
  
  while (true)
  {
    { 
       boost::lock_guard&lt;boost::recursive_mutex&gt; lock(mutex_);
       map::iterator it = m_map.begin();   
       while (it != m_map.end())
       {
           ioService.post(boost::bind(&amp;ProcessFun, this, it));
           ++it;    
       }
  
      ioService.run(); &lt;-- main thread is stuck here..  
     }
  
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>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?</p>