1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Locking without transactions</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> 9 <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" /> 10 <link rel="up" href="lock.html" title="Chapter��15.�� The Locking Subsystem" /> 11 <link rel="prev" href="lock_page.html" title="Locking granularity" /> 12 <link rel="next" href="lock_twopl.html" title="Locking with transactions: two-phase locking" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Locking without transactions</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="lock_page.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��15.�� 23 The Locking Subsystem 24 </th> 25 <td width="20%" align="right">��<a accesskey="n" href="lock_twopl.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="lock_notxn"></a>Locking without transactions</h2> 35 </div> 36 </div> 37 </div> 38 <p>If an application runs with locking specified, but not transactions (for 39example, <a href="../api_reference/C/envopen.html" class="olink">DB_ENV->open()</a> is callsed with <a href="../api_reference/C/envopen.html#envopen_DB_INIT_LOCK" class="olink">DB_INIT_LOCK</a> or 40<a href="../api_reference/C/envopen.html#envopen_DB_INIT_CDB" class="olink">DB_INIT_CDB</a> specified, but not <a href="../api_reference/C/envopen.html#envopen_DB_INIT_TXN" class="olink">DB_INIT_TXN</a>), locks are 41normally acquired during each Berkeley DB operation and released before the 42operation returns to the caller. The only exception is in the case of 43cursor operations. Cursors identify a particular position in a file. 44For this reason, cursors must retain read locks across cursor calls to 45make sure that the position is uniquely identifiable during a subsequent 46cursor call, and so that an operation using <a href="../api_reference/C/dbcget.html#dbcget_DB_CURRENT" class="olink">DB_CURRENT</a> will 47always refer to the same record as a previous cursor call. These cursor 48locks cannot be released until the cursor is either repositioned and a 49new cursor lock established (for example, using the <a href="../api_reference/C/dbcget.html#dbcget_DB_NEXT" class="olink">DB_NEXT</a> 50or <a href="../api_reference/C/dbcget.html#dbcget_DB_SET" class="olink">DB_SET</a> flags), or the cursor is closed. As a result, 51application writers are encouraged to close cursors as soon as 52possible.</p> 53 <p>It is important to realize that concurrent applications that use locking 54must ensure that two concurrent threads do not block each other. 55However, because Btree and Hash access method page splits can occur at 56any time, there is virtually no way to guarantee that an application 57that writes the database cannot deadlock. Applications running without 58the protection of transactions may deadlock, and can leave the database 59in an inconsistent state when they do so. Applications that need 60concurrent access, but not transactions, are more safely implemented 61using the Berkeley DB Concurrent Data Store Product.</p> 62 </div> 63 <div class="navfooter"> 64 <hr /> 65 <table width="100%" summary="Navigation footer"> 66 <tr> 67 <td width="40%" align="left"><a accesskey="p" href="lock_page.html">Prev</a>��</td> 68 <td width="20%" align="center"> 69 <a accesskey="u" href="lock.html">Up</a> 70 </td> 71 <td width="40%" align="right">��<a accesskey="n" href="lock_twopl.html">Next</a></td> 72 </tr> 73 <tr> 74 <td width="40%" align="left" valign="top">Locking granularity��</td> 75 <td width="20%" align="center"> 76 <a accesskey="h" href="index.html">Home</a> 77 </td> 78 <td width="40%" align="right" valign="top">��Locking with transactions: two-phase locking</td> 79 </tr> 80 </table> 81 </div> 82 </body> 83</html> 84