12 Multiple Task Programming

Multi-Tasking Statements

The five statements that control multi-tasking are summarized below. All statements can be executed from the keyboard or within a program. They provide the capability for a primary task and one or more secondary tasks to share a terminal by allowing the primary task to attach the terminal to those tasks that require attention from the user.

NOTE: To execute a program that contains the REQUEST# and ATTACH # statements, start Eloquence by typing eloq and then run the program from within Eloquence. If you start Eloquence by typing eloq program name when you have a program that contains these statements, the program sets up a secondary task and then the same program that started the secondary task runs in the secondary task. In other words, the same program running in the primary task runs in the secondary task.

The REQUEST # Statement

The REQUEST # statement can only be executed from a primary task. Its syntax is as follows:

REQUEST # taskid [,result]

It requests the ownership of a secondary task whose taskid is specified. The optional result parameter indicates the outcome of the request. Omitting this parameter will cause an execution error if the request is unsuccessful. This statement must be executed successfully before a subsequent ATTACH # statement can be executed for the corresponding taskid.

The ATTACH # Statement

The ATTACH # statement can only be executed from a primary task. Its syntax is as follows:

ATTACH # taskid [,result]

Its function is to switch the terminal from the executing primary task to the designated secondary task whose taskid is specified. The optional result parameter indicates the outcome of the statement. Omitting this parameter will cause an execution error if the statement is unsuccessful. The secondary task must have previously been REQUESTed by the primary task. Note that when you attach to a secondary task, the primary task continues to operate.

The ATTACH Statement

Its syntax is as follows:

ATTACH

Operator control (that is, the terminal) is passed to the DETACHed task executing the ATTACH statement. The ATTACH statement can be executed in primary or secondary task. However, if executed in a secondary task and the terminal is assigned to another secondary task (another ATTACH #), it will be ignored.

Example:

   10 DETACH
   20 WAIT 5000
   30 DISP "Done!"
   40 ATTACH
   50 END
ATTACH to a secondary task; run the program. The terminal will switch back to primary task if executing DETACH statement. After 5 seconds the terminal will switch back to secondary task.

The DETACH Statement

The DETACH statement can only be executed from a secondary task. Its syntax is as follows:

DETACH

Operator control (that is, the terminal), is passed from the secondary task to the primary task that owns it.

The DETACH statement can also be executed by pressing CTRL D. This can be used when the user is unable to enter the DETACH statement because the keyboard is not enabled.

The RELEASE # Statement

The RELEASE # statement can only be executed from a primary task. Its syntax is as follows:

RELEASE #taskid

Its function is to terminate the ownership of the specified secondary task. After this statement is issued, another primary task can then REQUEST that secondary task number.

NOTE: If this statement is issued while a program is still running in the secondary task, that program will abort.


Eloquence Language Manual - 19 DEC 2002