Item Locks
Item locks can be used to prevent an item from being updated by more than one process at the same time. This maintains the integrity of the database while allowing multiple users access to other items in the same group.
Proc allows a reality process to take multiple locks on the same item (this will normally occur if the item is processed by a number of different routines, each of which locks the item) - each of these locks must be separately released.
The number maximum number of item locks that can be held on the database is user-defined.
Setting Item Locks
In a Proc, an item lock is set by executing the F-UREAD command.
You cannot lock an item if it is locked by another process; F-UREAD waits until the lock is released before continuing.
An item lock can be set on a nonexistent item. When creating a new item, the item can be locked before it is written to disk. The lock can also be cleared if a write operation is not carried out.
Clearing Item Locks
Item locks are cleared by one of the following:
- Writing to the locked item with F-WRITE.
- F-FREE command.
- Deleting the locked item with the F-DELETE command.
- Terminating the program.
Note
Within a transaction, release is deferred until the transaction is completed or aborted.
Efficiency Guidelines
- Delay the use of F-UREAD until the last possible moment so as to minimise delays to other programs.
- Release the item lock as soon as possible.
- Avoid other I/O statements between setting and releasing an item lock. In particular, try not to execute IN statements while a lock is set.
- If more than one lock is set at any one time, ensure that the order in which items are locked is the same throughout the system to avoid deadly embraces.
Transaction Handling
When using transaction handling and a transaction is in progress, the release of item locks set within a transaction is deferred until the transaction is completed or aborted. Therefore avoid the use of large transactions, particularly those started from TCL, since the holding of many locks can lead to a gradual system paralysis.