您的位置:首页 > 其它

boost之线程池使用实例

2017-10-18 16:43 344 查看
#pragma once

#ifndef THREAD_POOL_H
#define THREAD_POOL_H

#include "boost_comm.h"

using namespace std;

//using namespace boost::executors;
namespace seemmo
{
#ifdef  ENABLE_BOOST_THREAD
class thread_pool
{
public:
explicit thread_pool(int thread_nums = 24);
~thread_pool();
protected:
static thread_pool *instance()
{
static thread_pool inst(48);
return &inst;
}
private:
basic_thread_pool *tp;
boost::mutex mtx_;
public:
static void post_task(void(*work)());
};
#endif //  ENABLE_BOOST_THREAD
}

#endif // THREAD_POOL_H

#include "thread_pool.h"
#include "picture_search.h"

namespace seemmo
{
#ifdef ENABLE_BOOST_THREAD
thread_pool::thread_pool(int init_nums)
{
tp = new basic_thread_pool(init_nums);
}

thread_pool::~thread_pool()
{
delete tp;
}
void thread_pool::post_task(void(*work)())
{
instance()->tp->submit(work);
}
#endif
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: