Introduction

This document provides a context of how to use PXROS-HR API functions to terminate a task. There are two possible options for achieving it: self-termination and forced termination (done by another task). The document describes the limitations when the user wants such behaviour and what the issues are with restarting a task (terminating and then creating again). For use inside of an application, see TC39x Task Termination Example available from HighTec Content Manager.

Task termination applies to each core separately, meaning every core using task termination must have a running Task Release Service. For forced termination (one task terminates another task), the termination requester must be the owner (parent) of the task to be terminated. This requirement also guarantees the existence of these tasks on the same core as it is not possible to create a task on a different core than the requester task’s core.

Task termination is an asynchronous operation consisting of several steps done by different components.

Self-termination components:

  • Terminable task — a task that is going to terminate itself

  • Task Release Service — task responsible for cleaning up the terminated task system context

The terminable task calls PxTerminate(true) to release all resources allocated by the task. Then PxTerminate() calls PxDie() in the process, which is responsible for signaling the PXSERVICE_TASK_DIED event to the Task Release Service. Task Release Service then cleans up (releases) all the task system context.

self termination components
Fig. 1. Self-termination components simplified scheme

Forced termination components:

  • Terminator task — task terminating another task

  • Terminable task — a task that is going to be terminated

  • Task Release Service — task responsible for cleaning up the terminated task system context

The terminator task calls PxTaskForceTermination(TerminableTaskID) to kill the terminable task. The terminable task is forced to execute a force-termination wrapper to terminate itself. This wrapper calls PxTerminate(true) to release all resources allocated by the task, then calls PxDie(), which is responsible for signaling the PXSERVICE_TASK_DIED event to the Task Release Service. Task Release Service then cleans up (releases) all the task system context.

forced termination components
Fig. 2. Forced termination components simplified scheme

Chapter Termination provides more details about the task termination.