|
|
Resource Management Programmer's Guide: HP 3000 MPE/iX Computer Systems > Chapter 2 Managing Shared Resources with RINsManaging with Global RINs |
|
A RIN used to manage a resource being shared by unrelated processes is called a global RIN. You use global RINs when you are using RIN management to prevent simultaneous access to a resource by two or more processes that may not be located in the same job/session. Each global RIN is a positive integer that is unique within MPE XL. Global RINs are acquired and released through system commands, and locked and unlocked through system intrinsics. If your program has only standard user capabilities, it can lock only one global RIN (used at the unrelated process level) at a time. With MR capability, your program can lock two or more global RINs at the same time. You can acquire a global RIN with the :GETRIN command. Following is an example of a :GETRIN call:
where PASSWORD is a required password, a character string of up to eight alphanumeric characters, beginning with an alphabetic character. You use the RIN password to restrict the locking of global RINs to authorized users. Before you and other users can engage in global RIN management you must distribute the global RIN and its password to the other users. The user that acquires the global RIN is considered the owner of that RIN. You typically enter the :GETRIN command during a session when you decide to use global RINs in your program to manage a resource. As a result of the command, MPE XL makes a global RIN available for use from a pool of free global RINs, and displays the global RIN in the following manner:
Cooperating processes can use the RIN during the current session or during future jobs/sessions. A global RIN is available even when the owner is logged off. The global RIN is available until the owner of the RIN releases the RIN back to MPE XL with the :FREERIN command. The total number of global RINs that MPE XL can assign is specified when the system is configured, but can never exceed 1024. If all currently available global RINs are acquired by users, the operating system rejects your request and issues the following message:
In this case you must wait until a global RIN becomes available, or request that your System Manager raise the maximum number of global RINs that MPE XL can assign. For additional information about the :GETRIN command, refer to the MPE XL Commands Reference Manual (32650-90003). Your process can lock a global RIN using the LOCKGLORIN intrinsic. Once you have successfully locked the RIN, no other process can lock the same global RIN until you either unlock it with the UNLOCKGLORIN intrinsic, or your process terminates. While you have the global RIN locked, you are guaranteed exclusive access to the resource associated with the global RIN, so long as other processes first attempt to lock the same global RIN, prior to accessing the resource. Following is an example of a LOCKGLORIN intrinsic call:
The parameters specified in the example are described below.
You use the UNLOCKGLORIN intrinsic to unlock a global RIN your process has previously locked with LOCKGLORIN. Once your process unlocks the RIN, it is available to be locked by other LOCKGLORIN calls. Following is an example of an UNLOCKGLORIN intrinsic call:
The parameter specified in the above example is described below.
Appendix A contains a program that uses global RINs to manage access to records in a data file being shared among multiple readers/writers. The program can be considered to be part of a book record maintenance application used in a library. Specifically, the program updates the location field of a book record located in the data file. Consider, also, that the library has several sites where users can check out books. A librarian at each site has a terminal logged on to a session running the maintenance application. Different sessions, then, must be able to share access to the same data file for the purposes of updating book records. Anytime a book is checked in or checked out from any site, the data file is updated to reflect the new location of the book. For example, if a book is checked in, the librarian who receives the book must update the record associated with the book, changing the location from LOANED CARD# 451, DUE APRIL 1 to AVAILABLE so that the records reflect the current location of the book. A problem exists maintaining the integrity of the records when two or more librarians access the same record simultaneously. For example, if two librarians, "A" and "B", access a book record simultaneously, the following may occur if provisions are not made to guarantee exclusive access to a record during updates:
The final result of this sequence is "B" overwriting the updated location entered by "A". The true location of the book has been lost. What should have occurred is that "B" should not have been able to access the record for the purposes of updating until "A" was finished with the update process. Appendix A shows a program using the LOCKGLORIN and UNLOCKGLORIN intrinsics to ensure exclusive access to book records during an update. The program allows a user to lock four records in a file so that a record can be updated without chance of another user updating it simultaneously. In the program, the other users are not suspended when attempting to access records elsewhere in the file. The file BOOKFILE, illustrated in Example 2-1, contains the titles and status of the 20 books in a library. The program in Appendix A uses this file as its data file. Figure 2-1 FIGURE 2-1
Example 2-1. BOOKFILE Contents. BOOKFILE contains 20 records, so the program must acquire five global RINs. (The program uses four records per global RIN). This is accomplished by repeatedly issuing the command:
BOOKRIN is the rinpassword specified in the program to lock the global RIN. Because MPE XL does not always assign global RINs in sequence, and because the program requires consecutive RINs to keep track of them more easily, it may be necessary to enter more :GETRIN commands before the program is first run in order to acquire the five consecutive global RINs. Extra RINs can be released with the :FREERIN command. For the purposes of this example, we assume that RINs 1 through 5 have been assigned. The program in Appendix A uses the following procedures to accomplish its task:
Figure 2-2 Figure 2-2.
Example 2-2. Procedure Access_Record_Exclusively. Once the user selects a valid book record, and the correct RIN is computed, the program calls the intrinsic LOCKGLORIN to lock the RIN. If the RIN is already locked (by another process executing the same code to update a record), the record cannot be accessed until the RIN is unlocked by the process that first locked it. Example 2-3 is a sample of an interactive session with the record update program located in Appendix A. Updated entries are accessed a second time to confirm successful modification. Figure 2-3 Figure 2-3
Example 2-3. Execution of Record Update Program. If you are the owner of a global RIN, you can use the :FREERIN command to release the global RIN back to the pool of free global RINs maintained by the operating system. Following is an example of a :FREERIN call:
where 8 is the global RIN you want released.
For additional information about the :FREERIN command, refer to the MPE XL Commands Reference Manual (32650- 90003). |
|