I use some code which implements tasks that may return. This code should not be changed, should stay portable.
Will FreeRTOSv8 delete task automatically after it returns?
If not
Here is old topic from FreeRTOS Support Archive.
you can place the return address that is on the inital stack (setup when the task is created) to jump to the delete function. Then it would happen automatically which is ok as long as this is what you expect to happen.
How can I implement this idea?
Another idea
I can create wrapper function:
struct delegate {
void(*task)(void*);
void *args;
};
task_wrapper( struct delegate *task )
{
task->task( task->args );
vTaskDelete( NULL );
}
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread , void *arg, int stacksize, int prio)
{
sys_thread_t createdTask;
struct delegate de = { thread, arg }; // created on stack. It may fail one day. Use malloc, or static...
int result;
result = xTaskCreate( task_wrapper, name, stacksize, &de, prio, &createdTask );
if( result == pdPASS ){
return createdTask;
}
return NULL;
}
but I think i is not good idea.