Abort Task

Text Language Definition

procedure AbortTask(TaskAddress:pointer);

Description

This command causes a procedure in the controller to abort execution.

A task can only be aborted with Abort Task if it had been started with Begin Task. A Task Identity is the procedure name that was used with the Begin Task command that started it.

After aborting a task it is often necessary to "clean up" the residual condition of resources the task had been managing. For example if a homing procedure was using the Jog command to home and was counting on the detection of a sensor to stop it, aborting the homing routine would leave the motor still jogging but with no reason to stop. If a task managing a blinking light is aborted the light might remain in an active condition. It is usually better to avoid using the Abort Task command and to instead have the task terminate itself, and clean up after itself, based on a boolean variable.

If remote resources are being used on a distributed controller network it is best to avoid using Abort Task since a remote command transaction might be disrupted leaving the remote resource in an unresponsive condition. If it is necessary to abort a task that is manipulating remote resources the following commands need to be used to insure that a remote transaction is not disrupted:

...
MasterComm.Mount(100,0);
AbortTask(TaskAddr(TaskManagingRemoteResources));
MasterComm.Dismount;

MasterComm is the shared object managing remote communication. It can only be used by one task at a time so it is managed with a Mutex, mutual exclusion mechanism. Remote actions will "Mount" the MasterComm so as to have exclusive use until the remote action is finished. When the remote action is finished it will dismount from the MasterComm so as to make the MasterComm available for other tasks. Other tasks needing to perform remote actions will wait until it is available which generally is only a controller sample period. The risk with aborting a task is that a task might be in the middle of a remote transaction. If that task is aborted the Mutex is never released and the MasterComm resource no longer available for any task to use. By calling MasterComm.Mount prior to performing an abort task the task performing the abort aquires the mutex and insures no other task has it. In this case it is safe to abort any other task. It is important to dismount when finished, and to do so promptly (within a half second), or a mount timeout will occur.

Escapes

The Abort Task block does not generate any escapes.

Examples

These first 3 figures illustrate how to use abort task to stop a light from blinking. However it leaves the job of insuring the light is off to the MouseUp procedure that is aborting the task:

A cleaner way to stop the light from blinking is to have a boolean variable that is set active when the task starts and turned off by the procedure that would like the task to stop. The process then manages its own resources rather than requiring the procedure doing the aborting to manage them:

Related Topics

Yield
Abort Task
Task Present
Schedule Task