Explicit Locking
When you let the file pool server automatically lock and unlock your BFS files, the implicit lock on a file remains in effect until the file is closed and the changes have been committed. If you want a lock to remain in effect longer than this, you must explicitly lock the file by entering a CREATE LOCK command before running your program or by calling the DMSCRLOC (Create Lock) routine within your program. This section discusses using the DMSCRLOC routine. For more information on the CREATE LOCK command, see the z/VM: CMS User's Guide and the z/VM: CMS Commands and Utilities Reference.
The DMSCRLOC routine allows you to explicitly lock a BFS file. Explicit locks are sometimes called check-out locks because you are checking out a file just as you would check out a book at a library. With the DMSCRLOC routine you can specify both the duration of the lock and the type of lock.
- EXCLUSIVE
- An explicit exclusive lock type means there can be only one person accessing the file at a given time. If you create an exclusive lock, you are the only person that can read or write the file. It also prevents other users from getting any locks on the file. To obtain an exclusive lock, there cannot be any other types of locks on the file.
- UPDATE
- An explicit update lock type has the same effect as an explicit exclusive lock.
- SESSION
- An explicit session lock lasts until the end of the CMS session, or until it is specifically deleted (with the DELETE LOCK command or DMSDELOC routine), or until all user machine connections to the file pool are broken (for example, with the DMSPURWU routine).
- LASTING
- An explicit lasting lock lasts until it is deleted with the DELETE LOCK command or DMSDELOC routine. The lock lasts across CMS sessions and logon sessions. For example, if you create a LASTING lock on a file and then log off, the file is still locked even though you are not logged on.
You should use explicit locks whenever you want to control the activity on your files without revoking permissions. If, for example, you are rewriting a document that everyone has access to, and you do not want anyone to see the new draft until it is complete, you might create lasting exclusive locks on the document's files.
To request a lock, all activity in the affected file pool for the work unit must be committed. If there is any outstanding work on the file pool, the request fails.