Coder Social home page Coder Social logo

Comments (4)

ilg-ul avatar ilg-ul commented on June 2, 2024

for threads we should distinguish the memory required for the thread control block and the stack.

normally threadTerminate() should be used for a different thread (this restriction should be mentioned in the manual), and in this case the thread stack can be fully freed when terminate() returns.

for threadExit() things are a bit more complicated, since this function is called on the context of the current thread, which means the current stack cannot be freed while executing thread code, so the thread should be added to a list of threads to be deleted, and the list should be iterated by another thread and terminated threads will be finally deleted (usually this happens on the idle thread, but any other strategy is ok).

the conclusion is that threads exiting themselves may take a while to be deleted.

regarding the delete function, for consistency reasons, the CMSIS++ RTOS C API defines a os_thread_delete(), which deallocates the thread control block allocated by os_thread_new().

actually CMSIS++ defines two pairs of functions for each object, for example:

void os_thread_construct (os_thread_t* thread, const char* name, os_thread_func_t func, const os_thread_func_args_t args, const os_thread_attr_t* attr);
void os_thread_destruct (os_thread_t *thread);

and

os_thread_t* os_thread_new (const char* name, os_thread_func_t func, const os_thread_func_args_t args, const os_thread_attr_t* attr);
void os_thread_delete (os_thread_t *thread);

the construct/destruct are exactly the C++ constructor/destructor, while new/delete are exactly the C++ new/delete, which, in addition to construct/destruct, allocate/deallocate memory for the thread control block.

this highly consistent mechanism is used for all CMSIS++ system objects.

from cmsis_5.

joabeck avatar joabeck commented on June 2, 2024

Ok now I know how this is solved in CMSIS++. But how is it handled in CMSIS 5. This is still unclear to me.
Thanks
Joachim

from cmsis_5.

ReinhardKeil avatar ReinhardKeil commented on June 2, 2024

CMSIS-RTOS2 has a thread attribute osThreadJoinable (see http://arm-software.github.io/CMSIS_5/RTOS2/html/group__CMSIS__RTOS__ThreadMgmt.html). When osThreadJoinable is not set osThreadTerminate instantly deletes the thread. When osThreadJoinable is set, you must use osThreadJoin to release the resources of the thread.

from cmsis_5.

ReinhardKeil avatar ReinhardKeil commented on June 2, 2024

closing as there is no further question on that

from cmsis_5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.