您当前的位置: 首页 > 

phymat.nico

暂无认证

  • 1浏览

    0关注

    1967博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

boost之线程池使用实例

phymat.nico 发布时间:2017-10-18 16:43:40 ,浏览量:1

#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
}

关注
打赏
1659628745
查看更多评论
立即登录/注册

微信扫码登录

0.0446s