From 64f0b85e4d5b0cbf1dc76eb3a5342403247576fe Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 24 Aug 2006 13:27:46 +0000 Subject: [PATCH] Use an extra bool variable to indicate thread validity --- source/thread.cpp | 6 +++--- source/thread.h | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) 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 &); -- 2.43.0