User`s manual

Dynamic C Users Manual digi.com 57
5.3.2 Costatement Syntax
The keyword costate identifies the statements enclosed in the curly braces that follow as a costatement.
costate [ name [state] ] { [ statement | yield; | abort; |
waitfor( expression ); ] . . .}
name can be one of the following:
A valid C name not previously used. This results in the creation of a structure of type CoData of the
same name.
The name of a local or global CoData structure that has already been defined
A pointer to an existing structure of type CoData
Costatements can be named or unnamed. If name is absent the compiler creates an unnamed structure of
type CoData for the costatement.
state can be one
of the following:
always_on
The costatement is always active. This means the costatement will execute every time it is encoun-
tered in the execution thread, unless it is made inactive by CoPause(). It may be made active
again by CoResume().
init_on
The costatement is initially active and will automatically execute the first time it is encountered in
the execution thread. The costatement becomes inactive after it completes (or aborts). The costate-
ment can be made inactive by CoPause().
If state is absent, a named costatement is initialized in a paused init_on condition. This means that
the costatement will not execute until CoBegin() or CoResume() is executed. It will then execute
once and become inactive again.
Unnamed costatements are always_on. You cannot specify init_on without specifying a costatement
name.
5.3.3 Control Statements
This section describes the control statements identified by the keywords: waitfor, yield and abort.
waitfor ( expression );
The keyword waitfor indicates a special waitfor statement and not a function call. Each time
waitfor is executed, expression is evaluated. If true (non-zero), execution proceeds to the next state-
ment; otherwise a jump is made to the closing brace of the costatement or cofunction, with the statement
pointer continuing to point to the waitfor statement. Any valid C function that returns a value can be
used in a waitfor statement.
Figure 5-2 shows the execution thread through a costatement when a waitfor evaluates to false. The
diagram on the left side shows which statements are executed the first time through the costatement. The
diagram on the right shows that when the execution thread again reaches the costatement the only state-
ment executed is the waitfor. As long as the waitfor continues to evaluate to false, it will be the only
statement executed within the costatement.