00001 #include "ug_thread_pool.h"
00002 namespace ug {
00003
00004 ThreadPool::
00005 ThreadPool(size_t const num_workers)
00006 : m_service(), m_busywork(new boost::asio::io_service::work(m_service))
00007 {
00008 m_workers.reserve(num_workers);
00009 for (size_t i = 0; i < num_workers; ++i)
00010 {
00011
00012
00013 boost::thread* t;
00014 t = new boost::thread(boost::bind(&service_t::run, &m_service));
00015 m_pool.add_thread(t);
00016
00017 }
00018 }
00019
00020 ThreadPool::
00021 ~ThreadPool()
00022 {
00023 m_busywork.reset();
00024 m_pool.join_all();
00025 m_service.stop();
00026 }
00027
00028
00029
00030
00031 }