//  // // ##### #### # # -= Threadux =-  // //  # # # ## ## Thread.cpp  // //  # # # ##  // //  # # # ### Thread creation and management  // //  # # # ## ##  // //  # #### # # R1 2004 by Markus Ewald  // //  // #ifndef THREADUX_THREAD_H #define THREADUX_THREAD_H #include "Threadux/Threadux.h" #include "Threadux/Interlocked.h" #include "Threadux/Gate.h" #include namespace Threadux { //  // //  Threadux::Thread  // //  // /// Thread encapsulation /** This class is used as a base class for threads and will execute its own operator () in a thread which can be started or stopped through the start() and terminate() methods. Through this class guarantees that the associated thread terminates when the instance is destroyed, it is required that both methods are called by the derived class because otherwise, the thread might access member variables or the derived class when it is not constructed yet or has already been destruced. */ class Thread { public: /// Constructor Thread(); /// Destructor virtual ~Thread() { terminate(); } // // Thread implementation // public: /// Wakes up the thread void wakeUp(); /// Starts the thread void start(); /// Terminate the thread void terminate(size_t Timeout = 5000); /// Check whether the thread's termination was requested bool terminationRequested() const { return m_bTerminateThread; } protected: /// Gate used to perform maintenance operations on the thread (eg. termination) Gate m_MaintenanceGate; private: struct Impl; /// The thread method virtual void operator()() = 0; /// Copy constructor Thread(const Thread &); /// Copy assignment operator void operator =(const Thread &); /// Private implementation details Impl *m_pImpl; /// Whether to terminate the thread Interlocked m_bTerminateThread; }; } // namespace KoCoS #endif // THREADUX_THREAD_H