Introduction to the locking subsystem

    The Lock subsystem is created, initialized, and opened by calls to with the DB_INIT_LOCK or flags specified.

    The DB_ENV->lock_vec() method is used to acquire and release locks. The method performs any number of lock operations atomically. It also provides the capability to release all locks held by a particular locker and release all the locks on a particular object. (Performing multiple lock operations atomically is useful in performing Btree traversals — you want to acquire a lock on a child page and once acquired, immediately release the lock on its parent. This is traditionally referred to as lock-coupling). Two additional methods, DB_ENV->lock_get() and , are provided. These methods are simpler front-ends to the DB_ENV->lock_vec() functionality, where acquires a lock, and DB_ENV->lock_put() releases a lock that was acquired using or DB_ENV->lock_vec(). All locks explicitly requested by an application should be released via calls to or DB_ENV->lock_vec(). Using instead of separate calls to DB_ENV->lock_put() and also reduces the synchronization overhead between multiple threads or processes. The three methods are fully compatible, and may be used interchangeably.

    The DB_ENV->lock_id() function returns a unique ID that may safely be used as the locker parameter to the method. The access methods use DB_ENV->lock_id() to generate unique lockers for the cursors associated with a database.

    The function provides the programmatic interface to the Berkeley DB deadlock detector. Whenever two threads of control issue lock requests concurrently, the possibility for deadlock arises. A deadlock occurs when two or more threads of control are blocked, waiting for actions that another one of the blocked threads must take. For example, assume that threads A and B have each obtained read locks on object X. Now suppose that both threads want to obtain write locks on object X. Neither thread can be granted its write lock (because of the other thread’s read lock). Both threads block and will never unblock because the event for which they are waiting can never happen.

    The DB_ENV->lock_stat() function returns information about the status of the lock subsystem. It is the programmatic interface used by the utility.

    The locking subsystem is closed by the call to DB_ENV->close().

    For more information on the locking subsystem methods, see the section in the Berkeley DB C API Reference Guide.