COBOL Manual for TNS and TNS/R Programs

Disk Input and Output
HP COBOL Manual for TNS and TNS/R Programs522555-006
28-39
Setting Time Limits on Input-Output Operations
To avoid deadlock when processes share and lock files, have each process lock and
unlock records and files in the same sequence.
Setting Time Limits on Input-Output Operations
Even when each program that shares files carefully arranges to lock files and records
in the same order, a newly introduced program or a change to an existing program can
fail to conform and cause deadlock. In HP COBOL, you can prevent this deadlock by
using the TIME LIMITS phrase with the statements OPEN, START, READ, and
LOCKFILE.
Without the TIME LIMITS phrase, if your process attempts to open a file, establish a
starting position in a file, read a file, or lock a file and that file or the necessary record
in that file is already locked, the process suspends activity until the lock is removed.
With the TIME LIMITS phrase, you can specify a time limit on the suspension. If the
time expires before the inhibiting lock is removed, the file operation terminates with file
status code “30” and GUARDIAN-ERR special register value 40. The program can
diagnose the failure of the file operation and either retry the operation or abandon the
current group of operations to allow another process to complete its operations.
Suppose you have a file declared by these entries:
SELECT OAK-FILE ASSIGN TO "$OAK.ACORN.TREE"
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS OAK-STATUS.
FD OAK-FILE
LABEL RECORDS ARE OMITTED.
01 OAK-RECORD.
02 ...
Suppose that you open the file with this statement:
OPEN INPUT OAK-FILE WITH TIME LIMITS SHARED.
Suppose that your program includes a declaratives section such as:
DECLARATIVES.
OAK-FILE-USE-SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON OAK-FILE.
OAK-DECL.
IF OAK-STATUS = "30"
AND GUARDIAN-ERR = 40
MOVE "Operation timed out on OAK file" TO REPORT
MOVE TIME-OUT-CODE TO OAK-ERROR
DISPLAY REPORT
END-IF.
END DECLARATIVES.
Note. If a process is protected by TMF, all locks are retained (despite unlocking statements)
until the current transaction is completed or backed out.