LOCK Statement

The LOCK statement sets an execution lock for the current process.

Format

LOCK expr [ELSE statements]

Parameter(s)

expr

expr evaluates to a number between 0 and 255, designating the LOCK number.

ELSE statements

If LOCK has already been set by another user, execute statements. If the ELSE clause is not specified, the program halts until the execution lock has been lifted.

Description

The LOCK statement sets an execution lock. The significance of each execution lock is designated by the application developer. By establishing a unique execution lock for a specific procedure, the programmer can ensure that two users cannot run the same procedure simultaneously.

Up to 256 execution locks are available on the mvBase system, numbered 0 to 255. The TCL command WHAT produces a list of all current execution locks and the process numbers which have set them.

For protecting file items, the READU, READVU, and MATREADU statements use a completely different method of item locking.

Execution locks, like file item locks, are automatically released at the end of the program. The UNLOCK statement can be used, however, to unlock a procedure before terminating the program.

Example

In this application the external subroutine REMOTE.MAIL uses a modem to send an electronic message to a remote system and then reports to the user that the message was successfully sent. By using the LOCK statement, it is ensured that two users will not use the modem at once. In this example, execution lock number 122 is the one that has been established for this subroutine.

The LOCK statement is actually called twice in the example. The first time it is called, an ELSE clause is included to give the user the chance to exit. If the user chooses not to exit, the LOCK statement is called again without an ELSE clause, and the program waits for the modem to be freed before continuing.

SUBROUTINE REMOTE.MAIL (MESSAGE, MODEMLINE)

LOCK 122 ELSE

   PRINT "MODEM IN USE. ABORT MESSAGE? (Y OR N)":

   INPUT ANSWER , 1

   IF ANSWER = "Y" THEN

      LOCK 122

   END ELSE

      GOSUB EXIT

   END

END

IF TA(MODEMLINE) THEN

   EXECUTE "PROTOCOL " : MODEMLINE : " (C)"

END

EXECUTE "LINE-ATT " : MODEMLINE

SEND "ATZ" TO MODEMLINE ELSE

   .

   .

   .

UNLOCK 122

RETURN

See Also

Statement and Function Reference