Implementation

In the reference implementation, the Task Release Service is a dedicated task responsible for cleaning up the task system context of the tasks terminated by the PxDie() function.

The TaskRS has to be started on each core where tasks are intended to be terminated and is responsible for calling the function PxDieService() when the kernel signals by the event PXSERVICE_TASK_DIED that a task has been terminated.

The TaskRS calls PxServiceTaskInit() to announce itself as the service task. This service task will get events to clean up the task system context after a task dies.

The Task Release Service can also be incorporated into a task that is not meant to be dedicated to releasing terminated tasks only but also serves additional functions. To properly manage and clean up tasks that have terminated, the PxDieService() method should be called. Note that since PxDieService() processes tasks through the PxDieSrv Task Release Queue, the cleanup procedure is not directly dependent on the PXSERVICE_TASK_DIED event. This flexibility in the cleanup mechanism means that you can call PxDieService() in various ways: it might be executed periodically, similar to a polling system, or it can be called after the forced termination function call.

task release service flow
Fig. 1. Minimal TaskRS implementation flow

Priority influence

The terminated tasks are cleaned after the PXSERVICE_TASK_DIED event is signalled, and the TaskRS gets execution time to process the event. TaskRS is subjected to the same scheduling rules as any other task in the system. Hence, its priority will have a major impact on the delay between the task termination request and the actual cleanup.

PxDieService()

PXROS-HR uses a queue (FIFO) of task IDs to be released — "PxDieSrv Task Release Queue" will be used in the following text. This queue is used only by the kernel.

PxDieService() goes through the PxDieSrv Task Release Queue until there is no task to be released, and for each such task, cleans up the task system context. The following steps are done:

  • Invalidates the task

  • Release the task’s private mailbox

  • Remove any allocated task stack memory

  • Remove any allocated task interrupt stack memory

  • Release the stack for the abort mechanism if not null

  • Return the task control block

  • Release the task object