#include Thread::Thread() { pthread_attr_init(&attribute); created = false; } Thread::Thread(int stacksize, int priority) { pthread_attr_init(&attribute); created = false; } Thread::~Thread() { // pthread_detach(thr); pthread_cancel(thr); } /* Make the name random enough so that nobody will use it */ static void* m9Tst3_a1i304(void* myarg) { Thread* th_ptr = (Thread*)myarg; th_ptr->Run(); pthread_exit(NULL); } void Thread::Start(void) { if ( created == false ) { pthread_create( &thr, &attribute, (void*(*)(void*)) m9Tst3_a1i304, (void*)this); created = true; } } void Thread::Yield(void) { // pthread_yield(); } void Thread::Detach(void) { pthread_detach(thr); } void Thread::ChkCancel(void) { pthread_testcancel(); } int Thread::Join(Thread* other_thread) { if( other_thread != NULL) return pthread_join(other_thread->thr, NULL); else return -1; } int Thread::Cancel(Thread *t) { if(t) return pthread_cancel(t->thr); else { // perror("pthread_cancel() failed"); return -1; } }