Chapter Contents

Previous

Next
cocall

cocall



Pass Control to a Coprocess


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTIONS
EXAMPLE


SYNOPSIS

#include <coproc.h>

void *cocall(coproc_t procid, void *arg);


DESCRIPTION

The cocall function gives control to a coprocess and passes it a pointer value. Execution of the calling coprocess is suspended until the called coprocess calls coreturn or is terminated. The procid argument identifies the coprocess to be called. The arg value is a value passed to the called coprocess. arg must not have the value CO_ERR . The arg value is passed to the called coprocess as follows: The arg value is passed to the called coprocess as follows:


RETURN VALUE

cocall returns a pointer specified by the called coprocess. Depending on the circumstances, any of the following can occur. If the called coprocess suspends itself by calling coreturn(val) , the value val is returned by cocall . If the called coprocess terminates by calling coexit(val) , the value val is returned by cocall . If the called coprocess terminates as a result of execution of return val; by its initial function, the value val is returned by cocall .

If the procid argument is invalid (that is, if it identifies an invalid or If the procid argument is invalid (that is, if it identifies an invalid or terminated coprocess), the calling coprocess is not suspended, and cocall immediately returns the constant CO_ERR .


CAUTIONS

Recursive cocall s are not allowed. While a coprocess is suspended as the result of a call to cocall , it cannot be cocalled again. In particular, the main coprocess can never be cocalled. Any attempt to perform a recursive cocall returns CO_ERR .


EXAMPLE

#include <stddef.h>
#include <coproc.h>
#include <stdlib.h>

coproc_t inp_proc;           /* input process process ID           */

void *input(void *);

char *file_name = "ddn:input";
char *input_ln;           /* a line of input, returned by inp_proc */

   /* Create and call a coprocess that reads a line of data from a */
   /* file. The "input" function, which is the initial function of */
   /* the new coprocess, is given in the EXAMPLE for coreturn.     */

inp_proc = costart(&input,NULL);          /* Create the coprocess. */

   /* Pass the input file name and check for error.                */
if (!cocall(inp_proc, file_name))
   exit(16);

for (;;) {
   input_ln = cocall(inp_proc, NULL);

         /* Ask for an input line; stop if no data left.           */
   if (!input_ln) break;
   .
   .   /* Process input data.                                      */
   .
}


Chapter Contents

Previous

Next

Top of Page

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