Advanced Topics
K
A
DAK
157
Termination Processing
AMX will only stop or kill a task which is running, waiting or ready to execute. A task
can be deleted if it is in any of these states or idle. Occasionally, a request to terminate a
task will occur while that task is performing some operation which AMX deems to be
critical. When this occurs, AMX allows the task to complete the critical operation and
then forces the abnormal termination. AMX does this so that none of its private
resources, such as message envelopes, are corrupted or lost.
When a task is stopped or killed, AMX ensures that a task waiting for its message to be
processed by the task being terminated, resumes and is not left blocked forever.
When a task is killed, AMX flushes each of the task's mailboxes. When doing so, AMX
examines the message. If the message indicates that a task is waiting for the message to
be processed, AMX allows the task to resume.
Deleting a task is a complex operation. AMX must make certain that the task is not
deleted until all currently active transactions involving that task have been completed.
For example, high priority Task A may be deleting medium priority Task B just as low
priority Task C was interrupted in its attempt to trigger Task B. The task trigger must be
allowed to complete in order that AMX task status not be compromised.
AMX meets these stringent requirements by requiring that you specify the priority at
which a task is to be deleted. The task deletion priority must be below that of all other
tasks with which it interacts but above any compute bound tasks which you may have.
AMX drops the task to its deletion priority which forces all other tasks with which the
task can interact to complete any outstanding operations before the deletion takes place.
AMX then deletes the task.
Once a request to delete a task has been made, no new transactions involving the deleted
task can occur. Any attempt to reference a task which has been marked for deletion will
produce an AERNST error indication since the deleted task no longer exists as far as you
are concerned. The actual task deletion may be delayed by AMX until current
transactions involving the task can be completed.
Termination Warning
When AMX stops, kills or deletes a task, it does not release any of the system resources
which that task may have within its control. Any interval timers, semaphores, event
groups, message exchanges, buffers or memory blocks which the task has reserved must
be released by the task's Task Termination Procedure when it is called by AMX.