File size: 642 Bytes
fd49381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "ug_thread_pool.h"
namespace ug {

ThreadPool::
ThreadPool(size_t const num_workers)
  : m_service(), m_busywork(new boost::asio::io_service::work(m_service))
{
  m_workers.reserve(num_workers);
  for (size_t i = 0; i < num_workers; ++i)
    {
      // boost::shared_ptr<boost::thread> t;
      // t.reset(new boost::thread(boost::bind(&service_t::run, &m_service)));
      boost::thread* t;
      t = new boost::thread(boost::bind(&service_t::run, &m_service));
      m_pool.add_thread(t);
      // m_workers.push_back(t);
    }
}

ThreadPool::
~ThreadPool()
{
  m_busywork.reset();
  m_pool.join_all();
  m_service.stop();
}




}