Within transactions, LOCKs are used by GT.M to ensure the ability to serialize. There is no guarantee, however, that attempts by other processes to examine LOCKs held with a transaction will produce the same results as when LOCKs are outside of a transaction. In other words, LOCKs within transactions should never be used as simple semaphores.
The LOCK command locks a specified resource name that controls a tree structured name space. Outside of transactions when one process in an environment acquires a LOCK or a ZALLOCATE on a named resource, no other GT.M process in that environment can LOCK a resource with an "overlapping" name until the first process releases the LOCK that it holds.
For information on the use of LOCKs within transactions, refer to Chapter 5: “General Language Features of M”.
LOCK Command Operation Summary | ||
---|---|---|
COMMANDS ISSUED |
RESULTING LOCKS |
COMMENTS |
L |
none |
Remove all prior locks. |
L A |
A |
Remove prior locks then lock A. |
L L +A |
A |
This sequence is equivalent to L A |
L A L -A |
none |
Remove prior locks before locking A, then remove lock on A. This is equivalent to L A L |
L A L +A L -A |
A |
Remove prior locks before locking A, increment lock on A without releasing prior lock on A, decrement lock on A without releasing prior lock on A. |
L A L +B |
A,B |
Remove prior locks before locking A, then lock B without releasing A. |
L A,B |
B |
Remove prior locks before locking A, unlock A, then lock B. |
L (A,B) |
A,B |
Remove prior locks before locking A and B simultaneously. |
L A L +B L +C |
A,B,C |
Remove prior locks before locking A, lock B without releasing A, lock C without releasing A and B |
L A L +(B,C) |
A,B,C |
Remove prior locks before locking A, lock B and C simultaneously without releasing A. |
L (A,B,C) L -B L -C |
A |
Remove prior locks before locking A, B, and C simultaneously, remove lock on B without releasing A and C, remove lock on C without releasing A. |
L (A,B,C) L -(B,C) |
A |
Remove prior locks before locking A, B, and C simultaneously, remove lock on B and C without releasing A. |
L (A,B) L -B |
A |
Remove prior locks before locking A and B simultaneously, remove lock on B without releasing A. |
Example:
Lock A,^B,@C Lock (A,B,@C)
The first LOCK command LOCKs A and unLOCKs A before LOCKing ^B, then unLOCKs ^B before locking the name specified by the variable C. The second LOCK command acquires all three resources at once. GT.M waits until all the named resources in the argument list become available before LOCKing all the resources. For example, if the resource specified by the variable C is not available for LOCKing, GT.M waits until that resource becomes available before LOCKing A and ^B.
Example:
LOCK (A,B) LOCK +C LOCK -B
This LOCKs A and B, then incrementally LOCKs C. Finally it releases the LOCK on B, while retaining the LOCKs on A and C.
Example:
LOCK (A,B,C) LOCK +(B,C) LOCK -(B)
This LOCKs A, B and C together. It then increments the lock "counts" of B and C. The last LOCK command removes one "count" of B, leaving one count of A and B and two counts of C.
Example:
LOCK ^D:5
This command attempts to LOCK ^D with a timeout of five seconds. If LOCK acquires the named resource before the timeout elapses, GT.M sets $TEST to 1 (TRUE). If LOCK fails to acquire the named resource before the timeout elapses, GT.M sets $TEST to 0 (FALSE).