NET/MASTER Network Control Language (NCL) Programmer's Guide
Synchronizing Access to Resources
Advanced NCL Programming
106160 Tandem Computers Incorporated 18–21
An NCL process can also use the LOCK verb to test whether any other NCL process is
holding a lock that it needs to access.
Waiting for Access to a Resource
If an NCL process issues a LOCK verb to request access to a resource lock, but the
required access is not available immediately, the WAIT operand specifies whether the
system returns control to the NCL process immediately or waits for the resource to
become available.
If you specify WAIT=YES, then the NCL process is suspended indefinitely until the
required resource lock can be obtained. This should be avoided unless you are certain
that you cannot get into a situation in which a needed resource is indefinitely locked
by another NCL process in the system (a deadly embrace).
Rather than specify WAIT=YES, it is recommended that you use the WAIT=number
option. This instructs the system to wait for the required lock for a certain number of
seconds rather than indefinitely. If the lock is not available after the specified time, the
NCL process resumes processing and avoids any deadlock conditions occurring.
Using Resources as
Semaphores
Using the LOCK verb to synchronize usage of a resource between competing NCL
processes solves the problem of access to real resources. You can use the same
technique to signal between cooperating NCL processes, in particular using the TEST
keyword of the LOCK verb. The TEST keyword inquires whether the specified
resource is already locked. In this case, the resource is not a real resource. Rather it is
signal or semaphore.
Semaphores are a useful mechanism for synchronizing the processing of related NCL
processes. In the following example PROCA needs to suspend processing until
PROCB reaches a particular point in its processing. The statement in PROCA that
suspends processing is the following:
LOCK WAIT=YES TYPE=TEST PNAME=XYZ
At this point, PROCA is suspended until another LOCK request is made for the
resource XYZ.
PROCB processes until it completes the function for which PROCA is waiting. At this
point, PROCB executes the following statement:
LOCK WAIT=YES TYPE=TEST PNAME=XYZ
Both the LOCK verbs complete with a return code of 8 in the system variable
&SYS.RETCODE. This indicates that both NCL process have reached the
synchronization point. If PROCB happens to reach the point first, its LOCK verb
suspends execution until PROCA executes its LOCK verb.
Displaying Information
About Locks
You can use the SHOW LOCKS command to display the locks held by the different
NCL processes in the system. To help you identify locks, the LOCK verb lets you
logically associate some text with the ownership of a lock. This text is shown in the
SHOW LOCKS display. It is also made available to an NCL process that executes
LOCK TYPE=TEST.