|
|
Resource Management Programmer's Guide: HP 3000 MPE/iX Computer Systems > Chapter 2 Managing Shared Resources with RINsManaging with Local RINs |
|
A RIN used to manage a resource being shared by related processes is called a local RIN. You use local RINs to prevent simultaneous access to a resource by two or more processes in the same job/session. Each local RIN is a positive integer that is unique within your job/session. Local RINs are assigned with the GETLOCRIN intrinsic, managed with the LOCKLOCRIN and UNLOCKLOCRIN intrinsics, and released with the FREELOCRIN intrinsic. You must acquire local RINs with the GETLOCRIN intrinsic before you can use them within your job/session. The following intrinsic call,
acquires six local RINs, RIN numbers 1 through 6, that can be used by the calling process as well as other processes in the same job/session. All local RINs you are planning to use in your program must be acquired in just one call to GETLOCRIN. If your program requires additional local RINs after the initial GETLOCRIN call, you must first release all local RINs then acquire the new number of local RINs with another GETLOCRIN call. You can lock a local RIN using the LOCKLOCRIN intrinsic. Once your process has successfully locked the RIN, no other process can lock the same local RIN until your process unlocks it with the UNLOCKLOCRIN intrinsic. While you have the local RIN locked, exclusive access is guaranteed only if other processes first attempt to lock the local RIN prior to accessing the resource associated with the locked RIN. A local RIN, acquired by your program, can be locked and unlocked by any process in your program's process structure. Following is an example of a LOCKLOCRIN intrinsic call from a program that has previously acquired local RINs 1 through 4:
The parameters specified in the example are described below.
You use the UNLOCKLOCRIN intrinsic to unlock a local RIN that has been previously locked by the calling process. Example 2-4 illustrates how the LOCKLOCRIN and UNLOCKLOCRIN intrinsics can be used by two processes executing in the same job/session. Assume that both the parent process (PARENT) and the child process (CHILD) are executing concurrently, line by line. Figure 2-4 Figure 2-4.
Example 2-4. Locking and Unlocking Local RINs. In Example 2-4, both processes have agreed to RIN management, associating RIN 1 (designated in the program as LPRIN) with a line printer (designated as LP). When PARENT first accesses LP, CHILD has not been created, and so RIN management is not yet required. To guarantee exclusive access to LP first, PARENT locks LPRIN before CHILD is activated. When PARENT finishes with LP, it unlocks LPRIN, thus making LPRIN available to be locked. In this case, CHILD has been blocked and is waiting for LPRIN to become available. When CHILD attempts to lock LPRIN, CHILD passes a value to LOCKLOCRIN indicating that execution should be blocked until LOCKLOCRIN can successfully return the locked RIN. The blocking occurs because PARENT currently has LPRIN locked. Execution continues only when PARENT unlocks LPRIN, thus making RIN 1 available to be locked by CHILD. While CHILD has LPRIN locked, PARENT is unable to lock LPRIN until it is unlocked by CHILD. You can use the FREELOCRIN intrinsic to release all local RINs your program previously acquired with GETLOCRIN. Following is an example of a call to FREELOCRIN:
Any process in your program's process structure can release local RINs. If you do not use FREELOCRIN to release local RINs, they are released to MPE XL when your program terminates. The LOCRINOWNER intrinsic identifies the process in your program's process structure that has a particular local RIN locked. If the RIN is locked by the parent of the calling process, LOCRINOWNER returns a zero. If the RIN is locked by any other process, LOCRINOWNER returns the Process Identification Number (PIN) of that process. Knowing the identity of the locking process is useful when parent and child processes are synchronizing access to one another through calls to the ACTIVATE and SUSPEND intrinsics. Example 2-5 is an example of RIN management where a parent process (PARENT) acts as a monitor for several child processes (one of whom is identified as CHILD1). Assume that both PARENT and CHILD1 are executing concurrently, line by line. Note that two agreements have been made by the programmer regarding RIN management prior to writing the code in Example 2-5.
Figure 2-5 Figure 2.5
Example 2-5. Identifying a Local RIN Locker. Both processes in Figure 2-5 share the following constants:
In Example 2-5, PARENT waits in a suspended state, unable to execute until an activation signal is received from a child process (in this case, by CHILD1 calling ACTIVATE). Once activated, PARENT locks SYNCHRIN to synchronize its communication with CHILD1. LOCRINOWNER determines the identity of the process that activated PARENT (the process that locked WHICHCHILD). PARENT then performs its required duty within the WHILE loop. PARENT activates the process that activated PARENT (CHILD1) then suspends itself to again await activation by a child process. Note that SYNCHRIN is passed as a parameter to SUSPEND. SUSPEND releases the RIN, making SYNCHRIN available to be locked by other processes. For details on using SUSPEND and ACTIVATE, refer to the discussion of suspending and activating processes in Process Management Programmer's Guide (32650-90023). |
|