#ifndef THREAD_THREAD_POOL_H #define THREAD_THREAD_POOL_H #include #include #include #include #include "base/base.h" namespace Hainan { class ThreadPool: private boost::noncopyable { private: int num; volatile int work_num; volatile bool running; boost::mutex mutex; boost::condition_variable cond; boost::condition_variable done; std::list threads; std::list > tasks; void Runner(); public: ThreadPool(); ~ThreadPool(); void Start(); void Stop(); void SetNum(int num); bool PushTask(boost::function task); }; typedef boost::shared_ptr ThreadPoolPtr; } // namespace Hainan #endif // THREAD_THREAD_POOL_H