CO-ROUTINES - summary of available B functions.

B Functions Available:

The B package supplies a set of basic primitives to allow co-routine processing: CREATE, RESUME, and DESTROY. CREATE will allocate and initialize a function control vector (FCV) to create an instance of a co-routine. RESUME will pass control from one co-routine to another. DESTROY will recover the space allocated for the FCV of a defunct co-routine.

Although the above three routines are sufficient for co-routine processing, the B package supplies a number of additional functions to make programming easier.

Each co-routine has a vector of user specified size (possibly zero) allocated with its FCV. This is particularily useful in simulation for storing such things as the head and tail pointers to a list to transactions, queued for a server modelled by that co-routine.

The B package also supports a parent-child relationship between co-routines. Besides the use of RESUME, another co-routine may be invoked by the use of CALL. This establishes the calling routine as the parent of the called routine (the child). A child co-routine may return control to its parent with a call to DETACH, without explicitly naming or knowing the identity of the parent. The parent is inherited by any routine RESUME'd by the child. In fact, the routine that does the DETACH is normally not the co-routine named in the original CALL by the parent.

For "break" key handling, .COBRK allows the user to specify a co-routine to which control will be passed whenever the "break" key is hit.

There are several routines that a user may invoke to obtain information about his state. TYPE tells how a co-routine last received control; PASSER returns the address of the FCV of the routine which last passed control to a specific co-routine; CALLER returns the address of the FCV of the parent co-routine; WMI returns the address of the FCV of the current co-routine; and SSIZE determines the amount of user specified description there is in an FCV.

There are two more routines for changing state. CALLBY artificially sets the parent, and ENDING determines what happens if a co-routine does a standard function return instead of a CALL, RESUME or DETACH.

Copyright © 1996, Thinkage Ltd.