Guardian Programmer's Guide

Table Of Contents
Using Nowait Input/Output
Guardian Programmer’s Guide 421922-014
4 - 11
Applying Nowait Operations to Multiple Files
parameter of the AWAITIO[X] procedure to -1. When AWAITIO[X] returns, it sets the
file-number parameter to the number of the file whose I/O operation finished.
If you issue just one I/O operation at a time to each file, then the file number returned
by the AWAITIO[X] procedure is enough to identify the completed operation. However,
it is often easier to use tags as described in the previous subsection.
A typical use for executing concurrent I/O operations against more than one file might
be when a process communicates with more than one terminal. The problem with
using waited I/O is that your program might, for example, issue a WRITEREADX call to
the terminal of a user who has left the office. The user of the other terminal is locked
out by this action, because the program waits indefinitely on the WRITEREADX call.
Using nowait I/O, the WRITEREADX call can be issued to both terminals; the process
responds to the terminal that replies:
NOWAIT^DEPTH := 1;
ERROR := FILE_OPEN_(TERM1:LENGTH,
TERM^NUM1,
!access!,
!exclusion!,
NOWAIT^DEPTH);
IF ERROR <> 0 THEN ...
ERROR := FILE_OPEN_(TERM2:LENGTH,
TERM^NUM2,
!access!,
!exclusion!,
NOWAIT^DEPTH);
IF ERROR <> 0 THEN ...
.
.
CALL WRITEREADX(TERM^NUM1,
BUFFER1,WCOUNT1,
RCOUNT1,TAG1);
IF <> THEN ...
CALL WRITEREADX(TERM^NUM2,
BUFFER2,WCOUNT2,
RCOUNT2,TAG2);
IF <> THEN ...
.
.
ANY^FILE := -1;
CALL AWAITIOX(ANY^FILE,
!buffer^address!,
BYTES,
TAG);
.
.
In the skeleton code shown above, the file number associated with the file of the
completed I/O operation is returned in ANY^FILE. The program can now use the
variable ANY^FILE to identify the active terminal, so it knows how to process the data
read by this operation.