projects
/
libs
/
core.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
668be79
)
Use an extra bool variable to indicate thread validity
author
Mikko Rasa
<tdb@tdb.fi>
Thu, 24 Aug 2006 13:27:46 +0000
(13:27 +0000)
committer
Mikko Rasa
<tdb@tdb.fi>
Thu, 24 Aug 2006 13:27:46 +0000
(13:27 +0000)
source/thread.cpp
patch
|
blob
|
history
source/thread.h
patch
|
blob
|
history
diff --git
a/source/thread.cpp
b/source/thread.cpp
index 384657397337813102aef1f8fe74dec9405bc2c0..6bc744422c55555bc11e8751618101db1d8a6d29 100644
(file)
--- a/
source/thread.cpp
+++ b/
source/thread.cpp
@@
-10,18
+10,18
@@
namespace Msp {
void *Thread::join()
{
- if(!
threa
d_)
+ if(!
vali
d_)
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 a115853211ba122ddb3628326339d43473474a0b..b9910ff2135cfaab67c30cbfe71d21b23f741516 100644
(file)
--- 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 &);