Execution and Item Locks

Locks are flags set to disable certain normal functions. Two types of lock can be set from DataBasic.

Note: Item locks are also set when editing an item using EDITOR or Screen Editor (except when in 'browse' mode), and can be set from Proc and ALL. Execution locks can also be set from Proc using the PLn command.

Execution Locks

In a DataBasic program, an execution lock is set using the LOCK statement. Each execution lock is assigned a number from 0 to 255. So, for example, execution lock '54' is set by a program using the LOCK 54 statement. If that lock is not already set, then the LOCK statement sets it, then executes a THEN clause (if any). The THEN clause may execute a series of statements to access a file or item, or use some other user-defined resource. If the specified lock is already set by another process, then the LOCK statement will fail and will execute an ELSE clause., if specified. The program halts at the LOCK statement awaiting release if the lock is already set and no ELSE clause is specified.

The execution lock does not, of itself, prevent another process from executing. It only prevents another process from setting the same execution lock. In the example above, the second process is only allowed to set the execution lock and execute statements in the THEN clause (or those following the LOCK statement when lock 54 is cleared by the first process.

Note therefore that an execution lock is only effective when programs cooperate using the LOCK/UNLOCK statements and appropriate lock numbers.

Execution locks are cleared by one of the following:

Go to top buttonItem Locks

Item locks 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.

DataBasic allows you 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 DataBasic program, an item lock is set by executing one of the following statements: READU, READVU, MATREADU.

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:

Note: If an item lock is released during a transaction, release is deferred until the transaction is completed or aborted.

TCL Commands Related to Locks

Various TCL commands are available to administer locks on a database.

CLEAR-BASIC-LOCKS
Resets the 256 execution locks that can be set by DataBasic.

CLEAR-ITEM-LOCKS
Unlocks a specific item lock, all items for a port, or clears the item lock table.

LIST-ITEM-LOCKS
Lists current entries in the item lock table.

SHOW-ITEM-LOCKS
Lists items and processes currently being accessed or locked.

LIST-LOCKS
Displays all locks (system, item and execution) currently in use.

Go to top button