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

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.