NET/MASTER Network Control Language (NCL) Programmer's Guide

Synchronizing Access to Resources
Advanced NCL Programming
18–18 106160 Tandem Computers Incorporated
Synchronizing Access
to Resources
NCL applications that involve multiple users often need a mechanism for controlling
access by different users or NCL processes to the same data or resource.
This control is particularly important in NCL systems that use user databases (UDBs)
or global vartables, which hold data that may be updated by some users while being
read by others.
NCL provides a method of controlling access to resources using advisory locks.
Advisory locks are locks that allow or deny access to resources providing all
applications agree to use the lock. It is important for all NCL processes that require
access to the same resource to agree on the name of the lock that is used to control
access.
Locks are also used to synchronize activity between separate NCL processes. This is
called using semaphores.
The LOCK verb controls access to resources. The SHOW LOCKS command displays
the locks held by different NCL processes. Table 18-3 summarizes the verb and
NonStop NET/MASTER MS commands discussed in this subsection.
Table 18-3. Verbs and Commands Used With Locks
Verb or Command Description
LOCK verb Controls access to a resource required by multiple NCL processes.
PURGE LOCK command Purges the specified resource lock.
SHOW LOCKS command Displays the current status of resource locks.
For the complete syntax of verbs, refer to the NonStop NET/MASTER NCL Reference
Manual. For the complete syntax of NonStop NET/MASTER MS commands, refer to
the NonStop NET/MASTER MS Command Reference Manual.
Resources Locks control access to resources. A resource is a name, consisting of a primary name
and an optional minor name.
You can use locks to ensure that a specific operation can be performed without
interference by other NCL processes that may be attempting to use the same data at
the same time. A typical example is the case where an NCL process needs to update a
record in a UDB.
The NCL process reads the target record, changes it, and writes it back to the file. It
also needs to guarantee that no other NCL process updates the same record at the
same time.
To achieve this guarantee, the NCL process first obtains exclusive access to a resource
that symbolizes the record update process. Once it has obtained this exclusive access,
the NCL process is free to perform as much work on the target record as it needs. It
knows that no other NCL process can access the same record at the same time because
no other NCL process is able to gain access to the resource lock.