<!--$Id: nondb.html,v 1.2 2004/03/30 01:22:53 jtownsen Exp $--> <!--Copyright 1997-2003 by Sleepycat Software, Inc.--> <!--All rights reserved.--> <!--See the file LICENSE for redistribution information.--> <html> <head> <title>Berkeley DB Reference Guide: Locking and non-Berkeley DB applications</title> <meta name="description" content="Berkeley DB: An embedded database programmatic toolkit."> <meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++"> </head> <body bgcolor=white> <a name="2"><!--meow--></a> <table width="100%"><tr valign=top> <td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Locking Subsystem</dl></h3></td> <td align=right><a href="../lock/am_conv.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../log/intro.html"><img src="../../images/next.gif" alt="Next"></a> </td></tr></table> <p> <h3 align=center>Locking and non-Berkeley DB applications</h3> <p>The Lock subsystem is useful outside the context of Berkeley DB. It can be used to manage concurrent access to any collection of either ephemeral or persistent objects. That is, the lock region can persist across invocations of an application, so it can be used to provide long-term locking (for example, conference room scheduling).</p> <p>In order to use the locking subsystem in such a general way, the applications must adhere to a convention for identifying objects and lockers. Consider a conference room scheduling problem, in which there are three conference rooms scheduled in half-hour intervals. The scheduling application must then select a way to identify each conference room/time slot combination. In this case, we could describe the objects being locked as bytestrings consisting of the conference room name, the date when it is needed, and the beginning of the appropriate half-hour slot.</p> <p>Lockers are 32-bit numbers, so we might choose to use the User ID of the individual running the scheduling program. To schedule half-hour slots, all the application needs to do is issue a <a href="../../api_c/lock_get.html">DB_ENV->lock_get</a> call for the appropriate locker/object pair. To schedule a longer slot, the application needs to issue a <a href="../../api_c/lock_vec.html">DB_ENV->lock_vec</a> call, with one <a href="../../api_c/lock_get.html">DB_ENV->lock_get</a> operation per half-hour -- up to the total length. If the <a href="../../api_c/lock_vec.html">DB_ENV->lock_vec</a> call fails, the application would have to release the parts of the time slot that were obtained.</p> <p>To cancel a reservation, the application would make the appropriate <a href="../../api_c/lock_put.html">DB_ENV->lock_put</a> calls. To reschedule a reservation, the <a href="../../api_c/lock_get.html">DB_ENV->lock_get</a> and <a href="../../api_c/lock_put.html">DB_ENV->lock_put</a> calls could all be made inside of a single <a href="../../api_c/lock_vec.html">DB_ENV->lock_vec</a> call. The output of <a href="../../api_c/lock_stat.html">DB_ENV->lock_stat</a> could be post-processed into a human-readable schedule of conference room use.</p> <table width="100%"><tr><td><br></td><td align=right><a href="../lock/am_conv.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../log/intro.html"><img src="../../images/next.gif" alt="Next"></a> </td></tr></table> <p><font size=1><a href="../../sleepycat/legal.html">Copyright (c) 1996-2003</a> <a href="http://www.sleepycat.com">Sleepycat Software, Inc.</a> - All rights reserved.</font> </body> </html>