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 }
相关文章推荐
- Quartz入门实例10-使用Quartz默认的线程池
- JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecutor)使用简介,线程邮件发送实例
- LinuxC/C++编程基础(21) 使用boost::asio搭建服务器简单实例(续)
- linux 下epoll与线程池结合使用的简单实例(含常用函数解释)
- boost的库中bind和function使用实例
- boost之asio同步io使用实例
- boost asio--作为线程池使用
- 线程池使用实例
- 线程池实例:使用Executors和ThreadPoolExecutor
- boost之内存池使用实例
- boost之asio异步io使用实例
- 使用boost中的线程池
- boost之无锁队列使用实例
- boost:exception使用实例
- boost.array 使用实例
- boost 中使用 线程池threadpool
- boost::asio 使用实例
- linux 下epoll与线程池结合使用的简单实例
- 在web项目中使用线程池发送邮件实例
- boost::threadpool线程池使用实例