Advanced Topics
K
A
DAK
153
13.4 Abnormal Task Term inati on
A task is a procedure which is called by the AMX Task Scheduler. The task ends
execution normally by returning to AMX. AMX provides procedure ajend which can be
used by a task to end execution and return to AMX under circumstances in which its
stack is deeply nested.
These two methods by which a task may end execution are considered normal
termination. A task has to be running to end in this fashion. No other task can force a
task, other than itself, to end.
AMX also provides a set of services which permit one task to force the abnormal
termination of another task. These services are not to be treated lightly. Their
description has been deferred to this chapter to indicate that they should be rarely
invoked.
It is assumed that you have read Chapter 3 of this manual and are familiar with the AMX
Task State Diagram presented in Figure 3.2-1.
The ability to arbitrarily terminate a task is one of the most abused privileges afforded by
some multitasking systems. The AMX philosophy is to encourage well structured task
designs in which there is rarely the need for an uncontrolled task termination. In many
cases, a modification to your system design can eliminate the apparent need to arbitrarily
terminate a task. However, occasionally system design does demand that an erring task
be eliminated for the good of all others. The availability of a controlled task termination
can greatly enhance your options in this case.
AMX offers the following task termination services:
ajtkstp AATKSTP Force a task to stop
ajtkill AATKILL Kill a task by forcing it to stop; flush its message mailboxes
ajtkdel AATKDEL Delete a task
ajtktrm AATKTRM Enable/disable abnormal task termination
The AMX termination services will not be included in your AMX system if your tasks do
not call any of these procedures.
Stop a Task
A task can be stopped. The effect is the same as if the task had just issued a call to ajend
to end its own operation. Only a task which is running, waiting or ready to execute can
be stopped. A task can stop itself.
A task that has been stopped does not cease to exist. It simply ends operation. If it has
outstanding trigger requests for execution, the task will be allowed to run again.
You must not stop any task which is waiting for a semaphore, an event group or a
message exchange.