Locking
The purpose of a lock is to obtain exclusive access to a system resource on a multi-user system. When a process sets a lock, it holds up any other process requiring the lock until it is released by the first process.
Item Locks
-
Delay item locking statements such as READU 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 INPUT statements while a lock is set.
-
Always use the LOCKED clause to take appropriate action as without this clause the process will loop waiting for the lock, thus wasting CPU time. You can use SYSTEM(43) to find out the number of the port that has locked the item.
-
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.
Note
-
If the use of an INPUT statement while a lock is set is unavoidable, use a FOR clause to time-out the user response and release the lock.
-
When using the LOCKED clause to SLEEP or RQM and then retry, choose the largest realistic wait time so as not to waste CPU time repeatedly retrying for the lock. If the program is interactive, consider displaying a warning message on the terminal, this reassures the user that the computer has not 'crashed' and also provides a visible indication if the application is running into lock problems.
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.
Execution Locks
Execution locks prevent multiple programs from executing all or a portion of DataBasic or Proc programs as defined by the same execution lock number. An execution lock does not, of itself, lock any file, group, item, or process.
Avoid the use of execution locks (LOCK and UNLOCK statements) to implement an item locking scheme. Improvements in the operation and use of read/update locks, and the introduction of item locks, alleviate most of the problems that warranted the use of execution locks in the past.
Read and Update Locks
Read and update locks (group locks) are used by the system when accessing items in files, therefore they are set and cleared by READ and WRITE and their variants. If many processes are accessing items in the same file group, collisions may occur. This may be alleviated by careful file sizing.