]> git.tdb.fi Git - libs/core.git/commitdiff
Use an extra bool variable to indicate thread validity
authorMikko Rasa <tdb@tdb.fi>
Thu, 24 Aug 2006 13:27:46 +0000 (13:27 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 24 Aug 2006 13:27:46 +0000 (13:27 +0000)
source/thread.cpp
source/thread.h

index 384657397337813102aef1f8fe74dec9405bc2c0..6bc744422c55555bc11e8751618101db1d8a6d29 100644 (file)
@@ -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);
 }
 
index a115853211ba122ddb3628326339d43473474a0b..b9910ff2135cfaab67c30cbfe71d21b23f741516 100644 (file)
@@ -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 &);