Skip to content
Snippets Groups Projects
Commit 1c0ef6cd authored by Matteo Pignataro's avatar Matteo Pignataro
Browse files

[ActiveObject] Bug fix about running flag

parent faf63358
No related branches found
No related tags found
1 merge request!89[ActiveObject] Fix running flag bug
...@@ -51,6 +51,8 @@ public: ...@@ -51,6 +51,8 @@ public:
/** /**
* @brief Start the thread associated with this active object. * @brief Start the thread associated with this active object.
* *
* @warning The method is not thread safe.
*
* Call stop() to terminate execution of the thread. * Call stop() to terminate execution of the thread.
* @return true if the thread has been started. * @return true if the thread has been started.
*/ */
...@@ -114,15 +116,16 @@ inline bool ActiveObject::start() ...@@ -114,15 +116,16 @@ inline bool ActiveObject::start()
if (!running) if (!running)
{ {
stopFlag = false; stopFlag = false;
running = true;
thread = miosix::Thread::create(threadLauncher, stackSize, priority, thread = miosix::Thread::create(threadLauncher, stackSize, priority,
reinterpret_cast<void*>(this), reinterpret_cast<void*>(this),
miosix::Thread::JOINABLE); miosix::Thread::JOINABLE);
if (thread != nullptr) if (thread == nullptr)
{ running = false;
running = true;
return true; return running;
}
} }
return false; return false;
...@@ -143,6 +146,7 @@ inline bool ActiveObject::shouldStop() { return stopFlag; } ...@@ -143,6 +146,7 @@ inline bool ActiveObject::shouldStop() { return stopFlag; }
inline void ActiveObject::threadLauncher(void* arg) inline void ActiveObject::threadLauncher(void* arg)
{ {
reinterpret_cast<ActiveObject*>(arg)->run(); reinterpret_cast<ActiveObject*>(arg)->run();
// When the run function ends, update the status // When the run function ends, update the status
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment