#ifndef _thread_h #define _thread_h #include const int DEFAULT = 0; // Thread is an abstract class. To use it // a new class has to be derived and a run function // has to be specified as void run(void) // Please don't change the class modifiers. They have been set // this way for a reason // Start class thread class Thread { public: Thread(); // For a list of valid priorities // look up manpage for pthread_attr_setprio Thread(int stacksize, int priority = DEFAULT); // Custom constructor not provided for portability // Almost everything that can be customized can // be done by using the above portable constructors // Thread(pthread_attr_t attr); virtual ~Thread(); void Start(); void Detach(void); void ChkCancel(void); static int Cancel(Thread *t); // Waits for the specified thread // This is invoked as a static function // since Joining is not property of a thread // For example, the main function can // Join one of the threads that it has created // even though it is not a thread object static int Join( Thread* other_thread); virtual void Run(void) = 0; static void Yield(void); private: bool created; pthread_t thr; pthread_attr_t attribute; }; #endif