diff options
-rw-r--r-- | raul/Thread.hpp | 5 | ||||
-rw-r--r-- | src/Thread.cpp | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/raul/Thread.hpp b/raul/Thread.hpp index 29cade1..14652c9 100644 --- a/raul/Thread.hpp +++ b/raul/Thread.hpp @@ -70,8 +70,13 @@ protected: * * This is called once on start, and terminated on stop. * Implementations likely want to put some infinite loop here. + * + * When _exit_flag becomes true (via a call to stop()) the loop + * should exit. */ virtual void _run() {} + + bool _exit_flag; private: diff --git a/src/Thread.cpp b/src/Thread.cpp index c0b570f..efa4c12 100644 --- a/src/Thread.cpp +++ b/src/Thread.cpp @@ -30,6 +30,7 @@ pthread_key_t Thread::_thread_key; Thread::Thread(const string& name) : _context(0) , _name(name) + , _exit_flag(false) , _pthread_exists(false) { pthread_once(&_thread_key_once, thread_key_alloc); @@ -41,6 +42,7 @@ Thread::Thread(const string& name) Thread::Thread(pthread_t thread, const string& name) : _context(0) , _name(name) + , _exit_flag(false) , _pthread_exists(true) , _pthread(thread) { @@ -86,7 +88,8 @@ void Thread::stop() { if (_pthread_exists) { - pthread_cancel(_pthread); + _exit_flag = true; + //pthread_cancel(_pthread); pthread_join(_pthread, NULL); _pthread_exists = false; cout << "[" << _name << " Thread] Exiting." << endl; |