Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 35
Monitoring Writes to a Disk File
4. The DO-UNTIL loop issues read operations against the file number returned by the
waited open. The loop exits when the READX procedure returns an end-of-file
error.
This operation serves the following purposes:
The first time through the loop, the calls to READX read any records that were
already written to the file.
In subsequent loops, the READX procedure reads the record at the end of the
file that was detected by the last CONTROL 27 operation that finished.
If the last CONTROL 27 operation finished because of some reason other than
appending a record to the file, the READX procedure returns an end-of-file
error on the first call. The operation that caused the CONTROL operation to
finish is ignored.
5. The AWAITIO procedure returns when the CONTROL 27 operation finishes; that
is, after a write operation to the file from any process has taken place.
6. The program issues another CONTROL 27 operation to wait for the next write to
the file.
Using SETMODE Function 146 With CONTROL Operation 27
If several processes issue CONTROL 27 operations against the same file, the effect
differs, depending on whether you use SETMODE function 146.
Several CONTROL 27 operations could be issued against the same file before there is
any write to the file. In this case, all CONTROL 27 operations normally finish when
one write to the file occurs. If you need only one of these processes to respond to a
new record, then you can use SETMODE function 146.
When you use SETMODE function 146, a write operation completes only one of the
pending CONTROL 27 operations. These operations are queued; therefore, the
operation that finishes is the last one that was still pending.
Once the CONTROL 27 operation finishes for a given process, that process should
read the new record and make sure no other process can read it, for example by
locking it. Next time a record gets written to the file, the process that is next on the
queue returns from its CONTROL 27 operation; the process skips over the locked
record and reads the record that was just added.
You set the mode as follows:
LITERAL YES = 1,
ONE^CONTROL27^AT^A^TIME = 146;
.
.
CALL SETMODE(FNUM,
ONE^CONTROL27^AT^A^TIME,
YES);
IF <> THEN ...