tk_ter_tsk
Terminate Task
ER ercd = tk_ter_tsk ( ID tskid ) ;
ID tskid Task ID
ER ercd Error code
E_OK Normal completion
E_ID Invalid ID number (tskid is invalid or cannot be used)
E_NOEXS Object does not exist (the task specified in tskid does not exist)
E_OBJ Invalid object state (the target task is in DORMANT state or is the invoking task)
Forcibly terminates the task specified in tskid.
This system call changes the state of the target task specified in tskid to DORMANT state.
Even if the target task was in a wait state (including SUSPEND state), the wait state is released and the task is terminated. If the target task was in some kind of queue (semaphore wait, etc.), executing tk_ter_tsk results in its removal from the queue.
This system call cannot specify the invoking task. If the invoking task is specified, error code E_OBJ is returned.
The relationships between target task states and the results of executing tk_ter_tsk are summarized in Table 4.1.
Target Task State
tk_ter_tsk ercd Parameter
Processing
RUN or READY state(except for invoking task)
E_OK
Forced termination
RUN state(invoking task)
E_OBJ
No operation
WAIT state
E_OK
Forced termination
DORMANT state
E_OBJ
No operation
NON-EXISTENT state
E_NOEXS
No operation
Table 4.1: Target Task State and Execution Result (tk_ter_tsk)
When a task is terminated by tk_ter_tsk, the resources acquired by the task up to that time (memory
blocks, semaphores, etc.) are not automatically freed. The user is responsible for releasing such resources efore the task terminates.
As a rule, the task priority and other information included in the TCB are reset when the task returns
to DORMANT state. If, for example, the task priority is changed by tk_chg_pri and later terminated
by tk_ter_tsk, the task priority reverts to the startup priority (itskpri) specified when the task was
started. It does not keep the task priority in e.ect at the time tk_ter_tsk was executed.
Forcible termination of another task is intended for use only by a debugger or a few other tasks closely elated to the OS. As a rule, this system call is not to be used by ordinary applications or middleware, for the following reason.
Forced termination occurs regardless of the running state of the target task.
If, for example, a task were forcibly terminated while the task was calling a middleware function, the
task would terminate right while the middleware was executing. If such a situation were allowed, normal operation of the middleware could not be guaranteed.
This is an example of how task termination cannot be allowed when the task status (what it is executing) is unknown. Ordinary applications therefore must not use the forcible termination function.

Comments