User`s manual

Dynamic C User’s Manual digi.com 67
5.5.7 Special Code Blocks
The following special code blocks can appear inside a cofunction.
everytime { statements }
This must be the first statement in the cofunction.
The everytime statement block will be executed on
every cofunc continuation call no matter where the statement pointer is pointing. After the every-
time statement block is executed, control will pass to the statement pointed to by the cofunction’s
statement pointer.
The everytime statement block will not be executed during the initial cofunc entry call.
abandon { statements }
This keyword applies to single-user cofunctions only and must be the first statement in the body of the
cofunction. The statements inside the curly braces will be executed if the single-user cofunction is forc-
ibly abandoned. A call to loophead() (defined in COFUNC.LIB) is necessary for abandon state-
ments to execute.
Example
Samples/COFUNC/ COFABAND.C illustrates the use of abandon.
In this example two tasks in main() are requesting access to SCofTest. The first request is honored
and the second request is held. When loophead() notices that the first caller is not being called each
time around the loop, it cancels the request, calls the abandonment code and allows the second caller in.
scofunc SCofTest(int i){
abandon {
printf("CofTest was abandoned\n");
}
while(i>0) {
printf("CofTest(%d)\n",i);
yield;
}
}
main(){
int x;
for(x=0;x<=10;x++) {
loophead();
if(x<5) {
costate {
wfd SCofTest(1); // first caller
}
}
costate {
wfd SCofTest(2); // second caller
}
}
}