Previous Topic: Associate Text with a Resource Lock

Next Topic: NCL Debug Facility

Resources as Semaphores

Using &LOCK to synchronize the use of a resource between competing processes solves the problem of access to real resources. The same technique can be employed to signal between co-operating processes, in particular with the use of the TEST facility of &LOCK. In this case, the resource is not a real resource but a signal or semaphore.

Semaphores are a useful mechanism for synchronizing the processing of related procedures. Take an example of Procedure A that needs to suspend processing until Procedure B reaches a particular point in its processing.

Procedure A's logic could look like this:

.
.  -* process
.
&LOCK WAIT=YES TYPE=TEST PNAME=XYZ 

At this point, Procedure A is suspended until another &LOCK request is made for the resource XYZ.

Procedure B in the meantime continues processing until it completes the function which it knows procedure A has to wait for. At this point, procedure B issues the same &LOCK request for the resource XYZ:

&LOCK WAIT=YES TYPE=TEST PNAME=XYZ

Both the &LOCK verbs complete with &RETCODE = 8, indicating that both procedures have reached the synchronization point. If Procedure B reaches the point first, its &LOCK would suspend it until Procedure A issued its &LOCK statement.