summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--raul/Thread.hpp1
-rw-r--r--src/Thread.cpp11
2 files changed, 9 insertions, 3 deletions
diff --git a/raul/Thread.hpp b/raul/Thread.hpp
index db35f77..50d7025 100644
--- a/raul/Thread.hpp
+++ b/raul/Thread.hpp
@@ -102,6 +102,7 @@ private:
unsigned _context;
std::string _name;
bool _pthread_exists;
+ bool _own_thread;
pthread_t _pthread;
};
diff --git a/src/Thread.cpp b/src/Thread.cpp
index 1d965ad..6f683bf 100644
--- a/src/Thread.cpp
+++ b/src/Thread.cpp
@@ -33,6 +33,7 @@ Thread::Thread(const string& name)
, _context(0)
, _name(name)
, _pthread_exists(false)
+ , _own_thread(true)
{
pthread_once(&_thread_key_once, thread_key_alloc);
pthread_setspecific(_thread_key, this);
@@ -45,6 +46,7 @@ Thread::Thread(pthread_t thread, const string& name)
, _context(0)
, _name(name)
, _pthread_exists(true)
+ , _own_thread(false)
, _pthread(thread)
{
pthread_once(&_thread_key_once, thread_key_alloc);
@@ -89,9 +91,12 @@ void
Thread::stop()
{
if (_pthread_exists) {
- _exit_flag = true;
- pthread_cancel(_pthread);
- pthread_join(_pthread, NULL);
+ if (_own_thread) {
+ _exit_flag = true;
+ pthread_cancel(_pthread);
+ pthread_join(_pthread, NULL);
+ }
+ _pthread = NULL;
_pthread_exists = false;
cout << "[" << _name << " Thread] Exiting." << endl;
}