diff --git a/src/shared/ActiveObject.h b/src/shared/ActiveObject.h index c26c6b2d902308ebd9821ee895bc8137f7f133e8..2d0c2ea82f89f123a032f3b8c2131c77f35f3e1c 100644 --- a/src/shared/ActiveObject.h +++ b/src/shared/ActiveObject.h @@ -51,6 +51,8 @@ public: /** * @brief Start the thread associated with this active object. * + * @warning The method is not thread safe. + * * Call stop() to terminate execution of the thread. * @return true if the thread has been started. */ @@ -114,15 +116,16 @@ inline bool ActiveObject::start() if (!running) { stopFlag = false; - thread = miosix::Thread::create(threadLauncher, stackSize, priority, - reinterpret_cast<void*>(this), - miosix::Thread::JOINABLE); - - if (thread != nullptr) - { - running = true; - return true; - } + running = true; + + thread = miosix::Thread::create(threadLauncher, stackSize, priority, + reinterpret_cast<void*>(this), + miosix::Thread::JOINABLE); + + if (thread == nullptr) + running = false; + + return running; } return false; @@ -143,6 +146,7 @@ inline bool ActiveObject::shouldStop() { return stopFlag; } inline void ActiveObject::threadLauncher(void* arg) { + reinterpret_cast<ActiveObject*>(arg)->run(); // When the run function ends, update the status