FORTRAN Reference Manual

Introduction to File I/O in the HP NonStop
Environment
FORTRAN Reference Manual528615-001
5-32
Read-Through Locks
However, your program can read a locked record, without waiting for the lock to be
released, by calling the Guardian SETMODE procedure to specify use of the
“readthrough locks” feature as follows:
CALL SETMODE (FILENUM (u), 4, 6, 0)
The SETMODE call tells the operating system to allow your program to read through
locks on the specified file. Call SETMODE after you have opened the file, but before
the first read from the file.
Then if you read a locked record, instead of waiting until the record is unlocked, your
FORTRAN program reads the record immediately and the READ statement’s IOSTAT
specifier returns error code 9 (locked record read) but the contents of the data record
are delivered intact. FORTRAN considers this code a warning rather than a serious
error.
The following example shows how your program might read a record:
READ (u, IOSTAT = error) data-list
IF (error .EQ. 9) error = 0
IF (error .NE. 0) handle-error
Because this technique defeats the purpose of record locks, your program might read
inconsistent data if you read the data before the updating process has completed its
work. Use this technique only in programs for which speed is more important than
accuracy and in which you understand how the records in the file are updated.