From: Mikko Rasa Date: Thu, 24 Aug 2006 13:27:46 +0000 (+0000) Subject: Use an extra bool variable to indicate thread validity X-Git-Tag: 1.0~48 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=64f0b85e4d5b0cbf1dc76eb3a5342403247576fe;p=libs%2Fcore.git Use an extra bool variable to indicate thread validity --- diff --git a/source/thread.cpp b/source/thread.cpp index 3846573..6bc7444 100644 --- a/source/thread.cpp +++ b/source/thread.cpp @@ -10,18 +10,18 @@ namespace Msp { void *Thread::join() { - if(!thread_) + if(!valid_) return 0; void *result; pthread_join(thread_, &result); - thread_=0; + valid_=false; return result; } Thread::~Thread() { - if(thread_) + if(valid) kill(SIGKILL); } diff --git a/source/thread.h b/source/thread.h index a115853..b9910ff 100644 --- a/source/thread.h +++ b/source/thread.h @@ -17,12 +17,13 @@ public: void kill(int s) { pthread_kill(thread_, s); } virtual ~Thread(); protected: - Thread() { } - void launch() { pthread_create(&thread_, 0, &main_, this); } + Thread(): valid_(false) { } + void launch() { if(!valid_) pthread_create(&thread_, 0, &main_, this); } virtual void *main()=0; void exit(void *r) { pthread_exit(r); } private: pthread_t thread_; + bool valid_; Thread(const Thread &); Thread &operator=(const Thread &);