Chapter Contents

Previous

Next
Coprocessing Functions

Coprocess States

During its execution, a coprocess may pass through up to five states:

The effect of cocalling a coprocess depends on its state at the time of the call. (The function costat enables you to determine the state of a coprocess.)

You may find it helpful to trace through one of the examples in this section for concrete illustration of the state transitions described here.

A coprocess is created by a call to the costart function. After its creation by costart , a coprocess is in the starting state until its execution begins as the result of a cocall . (Because the main coprocess is active when program execution begins, it is never in the starting state.) Each coprocess has an initial function, which is specified as an argument to costart when the coprocess is created. This is the function that is given control when the coprocess begins execution.

A coprocess is active when its statements are being executed. When a coprocess is cocalled, it becomes active if the cocall was legal. An active process cannot be cocalled; an attempt by a coprocess to cocall itself returns an error indication. At the start of execution, the main coprocess is in the active state.

A coprocess is busy when it has issued a cocall to some other coprocess and that coprocess has not yet performed a coreturn or terminated. A busy coprocess cannot be cocalled, and an attempt to do so returns an error indication. This means that a coprocess cannot cocall itself, directly or indirectly. One implication of this rule is that it is not possible to cocall the main coprocess.

A coprocess becomes idle (or suspended) when it has called coreturn , if the call was legal. An idle coprocess remains idle until another coprocess cocalls it, at which point it becomes active. The main coprocess is not permitted to call coreturn and, therefore, cannot become idle.

A coprocess is ended after its execution has terminated. Execution of a coprocess is terminated if it calls the coexit function, if its initial function executes a return statement, or if any coprocess calls the exit function. In the last case, all coprocesses are ended. In the other two cases, the coprocess that cocalled the terminating coprocess is resumed, as if the terminated coprocess had issued a coreturn . You cannot cocall a coprocess after it has ended.

The effect of the various routines that cause coprocess switching can be summarized as follows:
cocall can be used to resume a starting or idle coprocess. The active coprocess becomes busy and the cocalled coprocess becomes active.
coreturn can be used to suspend the active coprocess and resume the one that cocalled it. The active coprocess becomes idle, and the one that cocalled it changes from busy to active.
coexit can be used to terminate the active coprocess and resume the one that cocalled it. The active coprocess becomes ended, and the one that cocalled it changes from busy to active.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.