LOCK statement
Syntax
LOCK expression [THEN statements] [ELSE statements]
Description
Use the LOCK statement to protect specified user-defined resources or events against unauthorized use or simultaneous data file access by different users.
There are 64 public semaphore locks in the InfoSphere® DataStage® system. They are task synchronization tools but have no intrinsic definitions. You must define the resource or event associated with each semaphore, ensuring that there are no conflicts in definition or usage of these semaphores throughout the entire system.
expression evaluates to a number in the range of 0 through 63 that specifies the lock to be set. A program can reset a lock any number of times and with any frequency desired. If expression evaluates to the null value, the LOCK statement fails and the program terminates with a run-time error message.
If program B tries to set a lock already set by program A, execution of program B is suspended until the first lock is released by program A; execution of program B then continues.
The ELSE clause provides an alternative to this procedure. When a LOCK statement specifies a lock that has already been set, the ELSE clause is executed rather than program execution being suspended.
Program termination does not automatically release locks set in the program. Each LOCK statement must have a corresponding UNLOCK statement. If a program locks the same semaphore more than once during its execution, a single UNLOCK statement releases that semaphore.
The UNLOCK statement can specify the expression used in the LOCK statement to be released. If no expression is used in the UNLOCK statement, all locks set by the program are released.
Alternatively, locks can be released by logging off the system or by executing either the QUIT command or the CLEAR.LOCKS command.
You can check the status of locks with the LIST.LOCKS command; this lists the locks on the screen. The unlocked state is indicated by 0. The locked state is indicated by a number other than 0 (including both positive and negative numbers). The number is the unique signature of the user who has set the lock.
Example
The following example sets lock 60, executes the LIST.LOCKS command, then unlocks all locks set by the program:
LOCK 60 ELSE PRINT "ALREADY LOCKED"
EXECUTE "LIST.LOCKS"
UNLOCK
The program displays the LIST.LOCKS report. Lock 60 is set by user 4.
0:-- 1:-- 2:-- 3:-- 4:-- 5:-- 6:-- 7:--
8:-- 9:-- 10:-- 11:-- 12:-- 13:-- 14:-- 15:--
16:-- 17:-- 18:-- 19:-- 20:-- 21:-- 22:-- 23:--
24:-- 25:-- 26:-- 27:-- 28:-- 29:-- 30:-- 31:--
32:-- 33:-- 34:-- 35:-- 36:-- 37:-- 38:-- 39:--
40:-- 41:-- 42:-- 43:-- 44:-- 45:-- 46:-- 47:--
48:-- 49:-- 50:-- 51:-- 52:-- 53:-- 54:-- 55:--
56:-- 57:-- 58:-- 59:-- 60:4 61:-- 62:-- 63:--