Chapter Contents

Previous

Next
coreturn

coreturn



Return Control to a Coprocess


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
EXAMPLE


SYNOPSIS

#include <coproc.h>

void *coreturn(void *arg);


DESCRIPTION

coreturn returns control to the current cocaller of a coprocess and returns a pointer value. Execution of the returning coprocess is suspended until it is cocalled again. The arg value is a value to be returned to the cocaller of the current coprocess. arg must not have the value CO_ERR .

The arg value is passed to the resumed coprocess as follows. The arg value is passed to the resumed coprocess as follows. By necessity, the caller of the current process is suspended by executing the cocall function. This call is resumed and returns the value specified by arg to its caller.


RETURN VALUE

coreturn returns only when the current coprocess is cocalled again by some other coprocess. The return value is the arg value specified by the corresponding call to cocall .

An invalid call to coreturn immediately returns the value An invalid call to coreturn immediately returns the value CO_ERR .


CAUTION

coreturn cannot be called from the main coprocess because it has no cocaller to return to.


EXAMPLE

This example is a companion to the cocall example. It illustrates a coprocess whose purpose is to read a file and coreturn a line at a time.

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

void *input(void *filename)
{
   FILE *f;
   char buf [100];
   f = fopen(filename, "r");

       /* if open failed, quit, pass NULL to calling coprocess     */
   if (!f)
      coexit(NULL);

      /* else acknowledge valid name                               */
   coreturn(filename);
   for (;;) {
      fgets(buf, 100, f);            /* Read the next line.        */
      if (feof(f)) {                /* if reached end-of-file      */
         fclose(f);
         coexit(NULL);  /* Terminate coprocess and return NULL.    */
      }
            /* else pass back input line address                   */
      else coreturn(buf);
   }
}


Chapter Contents

Previous

Next

Top of Page

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