Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  /* Then activate the kernel thread at the provided priority */

  ret = task_activate((FAR struct tcb_s *)tcb);
  if (ret < 0)
    {
/* nxtask_unit() will undo all of the operations of nxtask_init().
* It also has the side-effect of freeing the TCB which it assumes
* was allocated with one of the kmm_malloc()functions.
*/
nxtask_uninit(tcb); custom_free(stack);
return ret;
}

return OK;

Freeing the TCB

Prior to calling nxtask_init(), the TCB  can be freed using the kmm allocator, specifically the function kmm_free().  However, after nxtask_init() is called, additional resources will be associated with the TCB and you must then call nxtask_uninit() to free the TCB and all of its associated resources.  kmm_free() will be used internally by nxtask_uninit() to free the TCB.  Note that in any event, the TCB must be allocated with one of the kmm_malloc() allocation functions.

Freeing the Custom Stack Memory

The effect of the TCB_FLAG_CUSTOM_STACK flag is the the OS will not attempt to free the custom stack memory if the kernel thread exits, crashes, or is killed.  Does this matter in your implementation?  Could this result in some kind of memory leak?  If any kind of clean-up is required by your application to free the custom stack memory, you will probably want to use an on_exit() or atexit() function to get a callback when the kernel thread is terminated.

...