| 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>Standard lock modes</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 16. The Locking Subsystem" /> |
| 11 | <link rel="prev" href="lock_max.html" title="Configuring locking: sizing the system" /> |
| 12 | <link rel="next" href="lock_dead.html" title="Deadlock detection" /> |
| 13 | </head> |
| 14 | <body> |
| 15 | <div xmlns="" class="navheader"> |
| 16 | <div class="libver"> |
| 17 | <p>Library Version 11.2.5.3</p> |
| 18 | </div> |
| 19 | <table width="100%" summary="Navigation header"> |
| 20 | <tr> |
| 21 | <th colspan="3" align="center">Standard lock modes</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="lock_max.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 16. |
| 26 | The Locking Subsystem |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="lock_dead.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="lock_stdmode"></a>Standard lock modes</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p>The Berkeley DB locking protocol is described by a conflict matrix. A |
| 42 | conflict matrix is an NxN array in which N is the number of different |
| 43 | lock modes supported, and the (i, j)th entry of the array indicates |
| 44 | whether a lock of mode i conflicts with a lock of mode j. In addition, |
| 45 | Berkeley DB defines the type <span class="bold"><strong>db_lockmode_t</strong></span>, which is the type of a |
| 46 | lock mode within a conflict matrix.</p> |
| 47 | <p>The following is an example of a conflict matrix. The actual conflict |
| 48 | matrix used by Berkeley DB to support the underlying access methods is more |
| 49 | complicated, but this matrix shows the lock mode relationships available |
| 50 | to applications using the Berkeley DB Locking subsystem interfaces directly.</p> |
| 51 | <div class="variablelist"> |
| 52 | <dl> |
| 53 | <dt> |
| 54 | <span class="term">DB_LOCK_NG</span> |
| 55 | </dt> |
| 56 | <dd>not granted (always 0)</dd> |
| 57 | <dt> |
| 58 | <span class="term">DB_LOCK_READ</span> |
| 59 | </dt> |
| 60 | <dd>read (shared)</dd> |
| 61 | <dt> |
| 62 | <span class="term">DB_LOCK_WRITE</span> |
| 63 | </dt> |
| 64 | <dd>write (exclusive)</dd> |
| 65 | <dt> |
| 66 | <span class="term">DB_LOCK_IWRITE</span> |
| 67 | </dt> |
| 68 | <dd>intention to write (shared)</dd> |
| 69 | <dt> |
| 70 | <span class="term">DB_LOCK_IREAD</span> |
| 71 | </dt> |
| 72 | <dd>intention to read (shared)</dd> |
| 73 | <dt> |
| 74 | <span class="term">DB_LOCK_IWR</span> |
| 75 | </dt> |
| 76 | <dd>intention to read and write (shared)</dd> |
| 77 | </dl> |
| 78 | </div> |
| 79 | <p>In a conflict matrix, the rows indicate the lock that is held, and the |
| 80 | columns indicate the lock that is requested. A 1 represents a conflict |
| 81 | (that is, do not grant the lock if the indicated lock is held), and a |
| 82 | 0 indicates that it is OK to grant the lock.</p> |
| 83 | <pre class="programlisting"> Notheld Read Write IWrite IRead IRW |
| 84 | Notheld 0 0 0 0 0 0 |
| 85 | Read* 0 0 1 1 0 1 |
| 86 | Write** 0 1 1 1 1 1 |
| 87 | Intent Write 0 1 1 0 0 0 |
| 88 | Intent Read 0 0 1 0 0 0 |
| 89 | Intent RW 0 1 1 0 0 0</pre> |
| 90 | <div class="variablelist"> |
| 91 | <dl> |
| 92 | <dt> |
| 93 | <span class="term">*</span> |
| 94 | </dt> |
| 95 | <dd>In this case, suppose that there is a read lock held on an object. A new |
| 96 | request for a read lock would be granted, but a request for a write lock |
| 97 | would not.</dd> |
| 98 | <dt> |
| 99 | <span class="term">**</span> |
| 100 | </dt> |
| 101 | <dd>In this case, suppose that there is a write lock held on an object. A |
| 102 | new request for either a read or write lock would be denied.</dd> |
| 103 | </dl> |
| 104 | </div> |
| 105 | </div> |
| 106 | <div class="navfooter"> |
| 107 | <hr /> |
| 108 | <table width="100%" summary="Navigation footer"> |
| 109 | <tr> |
| 110 | <td width="40%" align="left"><a accesskey="p" href="lock_max.html">Prev</a> </td> |
| 111 | <td width="20%" align="center"> |
| 112 | <a accesskey="u" href="lock.html">Up</a> |
| 113 | </td> |
| 114 | <td width="40%" align="right"> <a accesskey="n" href="lock_dead.html">Next</a></td> |
| 115 | </tr> |
| 116 | <tr> |
| 117 | <td width="40%" align="left" valign="top">Configuring locking: sizing the system </td> |
| 118 | <td width="20%" align="center"> |
| 119 | <a accesskey="h" href="index.html">Home</a> |
| 120 | </td> |
| 121 | <td width="40%" align="right" valign="top"> Deadlock detection</td> |
| 122 | </tr> |
| 123 | </table> |
| 124 | </div> |
| 125 | </body> |
| 126 | </html> |