#ifndef HEADER_BASE_RUNNABLE #define HEADER_BASE_RUNNABLE #include // about thread #include // for atomic_bool #include // for shared_ptr #include // for bind namespace base { class CRunnable { public: CRunnable() : _stop(true) {} virtual ~CRunnable() {} //base option virtual void Start() { _stop = false; if (!_pthread) { _pthread = std::shared_ptr(new std::thread(std::bind(&CRunnable::Run, this))); } } virtual void Stop() { _stop = true; } virtual void Join() { if (_pthread) { _pthread->join(); } } //TO DO virtual void Run() = 0; bool GetStop() { return _stop; } static void Sleep(int interval) { std::this_thread::sleep_for(std::chrono::milliseconds(interval)); } protected: CRunnable(const CRunnable&) = delete; CRunnable& operator=(const CRunnable&) = delete; protected: volatile std::atomic_bool _stop; std::shared_ptr _pthread; }; } #endif