9 #include <pthread.h> //Needed for threading
10 #include <signal.h> //Needed for killing the threads (why not in pthread.h?)
18 Thread() : finished(false), thread(0), started(false)
23 virtual void Start() = 0;
25 void Start(void* (ThreadFunction)(void*))
29 pthread_create(&(thread), NULL, ThreadFunction, (void*)(this));
30 pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
38 pthread_cancel(thread);
40 pthread_join(thread, NULL);
50 bool Finished() const {return finished;}
61 class GetterThread : public Thread
64 GetterThread(FILE * newStream, std::string & newBuffer) : Thread(), stream(newStream), buffer(newBuffer)
69 virtual ~GetterThread()
74 virtual void Start() {assert(&buffer != NULL); Thread::Start(GetMessage);}
82 static pthread_mutex_t mutex;
83 static void * GetMessage(void * p);
88 class TimerThread : public Thread
91 TimerThread(int newCount) : Thread(), count(newCount)
96 virtual ~TimerThread()
101 virtual void Start() {Thread::Start(Timeout);}
106 static void * Timeout(void * p);
110 #endif //THREAD_UTIL_H