Run to completion task in uCOS-III

Run to completion task in uCOS-III

Home Forums Real-Time Kernels Run to completion task in uCOS-III

This topic contains 2 replies, has 2 voices, and was last updated by  Michael Rausch 2 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #18777

    Michael Rausch
    Participant

    Hi,

    I know that a terminating task should call OSTaskDel.
    My question is about memory resources dynamically allocated at task creation for its stack and TCB.

    Is there a way to automatically free these resources at task deletion?

    Freeing the memory needed for the stack is possible by using a hook function (i.e. OSTaskDelHook).
    But what about the TCB memory, since it gets accessed even after this hook function is executed?

    Even OSTaskSwHook is not to a valid option.

    TIA,
    Mch

    #18813

    Matt Gordon
    Keymaster

    There is no automatic mechanism for freeing the TCB involved in a task delete call. The kernel gives application code the responsibility of allocating a TCB prior to each create call, and it similarly shifts responsibility for freeing TCBs to the application in systems that utilize the task delete function. Of course, the easiest way to ensure that task deletion and the associated TCB de-allocation are synchronized is to perform both in the same task, with de-allocation immediately following the delete. When it’s not possible for the delete and de-allocate code to share a task, it can be helpful to use a semaphore or event flag to signal the task handling the de-allocation upon completion of the delete operation.

    #18822

    Michael Rausch
    Participant

    Thank you Matt,

    I must correct my assertion about stack freeing.
    It’s not possible to do it from OSTaskDelHook because the stack gets accessed again at task switching, so only OSTaskSwHook is a candidate for that.
    In particular a proper function assigned to OS_AppTaskSwHookPtr can be used for stack disposal.
    The same is not possible for TCB freeing because the TCB may still get accessed afterwards if at least one of OS_CFG_TASK_PROFILE_EN, CPU_CFG_INT_DIS_MEAS_EN, OS_CFG_SCHED_LOCK_TIME_MEAS_EN or OS_CFG_TASK_STK_REDZONE_EN is set.
    An additional call to a hook function would be needed at the very end of OSTaskSwHook to make the “automatic” freeing of task resources possible (avoiding the need of an additional special de-allocation task).
    Of course this is valid int the assumption that the TCB of the deleted task is never accessed again by uCOS-III once it has been switched out.

    Best regards,
    Mch

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

View the complete site map

x
Loading...