Guardian Programmer's Guide

Table Of Contents
Guardian Programmer’s Guide 421922-014
3 - 1
3
Coordinating Concurrent File
Access
Several processes can access the same file at the same time. This section describes
the procedures that allow you to coordinate such concurrent access. Each process
indicates (when opening the file) how it intends to use the file, either by specifying the
access mode and the exclusion mode to the file or by accepting default values.
Topics covered in this section include:
How to set the access mode for a file; the access mode limits the operations to be
performed by the opener. The access mode is specified as read/write, read-only,
or write-only. Setting the Access Mode, below, provides details.
How to set the exclusion mode; the exclusion mode specifies how much access
other processes are allowed. It can provide shared, protected, or exclusive
access. Setting the Exclusion Mode, later in this section, shows how to do this.
How to apply a lock to a file that is already open. In addition to exclusion specified
at file-open time, the file system also allows you to apply a lock to a file that is
already open. You do this using the LOCKFILE procedure as described in Locking
a File in this section. You can also inadvertently cause your process to wait
indefinitely because it has to wait for a locked resource that never becomes
available. The last subsection, Avoiding Deadlocks, describes how to prevent this.
Locking issues regarding concurrent access at the record level, are not described here;
see Section 5, Communicating With Disk Files, for details. This section discusses file-
level concurrency issues.
Setting the Access Mode
When you open a file, you do so with an access mode that indicates what kind of
operations you will perform on the file once it is open. The access mode can allow you
to read and write to the file, perform only read operations, or perform only write
operations.
The third parameter of the FILE_OPEN_ procedure (the access p
arameter) specifies
the access mode. This parameter can have one of the following values:
0 Read/write access (the default access)
1 Read-only access
2 Write-only access
3 Extend access (applies to magnetic tape only—refer to Section 12,
Communicating With Magnetic Tape)