Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="condition-objects.html" /> | |
13 | <link rel="prev" href="lock-objects.html" /> | |
14 | <link rel="parent" href="module-threading.html" /> | |
15 | <link rel="next" href="condition-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>7.5.2 RLock Objects </title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="7.5.1 Lock Objects" | |
25 | href="lock-objects.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="7.5 threading " | |
28 | href="module-threading.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="7.5.3 Condition Objects" | |
31 | href="condition-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="lock-objects.html">7.5.1 Lock Objects</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="module-threading.html">7.5 threading </A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="condition-objects.html">7.5.3 Condition Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H2><A NAME="SECTION009520000000000000000"></A><A NAME="rlock-objects"></A> | |
56 | <BR> | |
57 | 7.5.2 RLock Objects | |
58 | </H2> | |
59 | ||
60 | <P> | |
61 | A reentrant lock is a synchronization primitive that may be | |
62 | acquired multiple times by the same thread. Internally, it uses | |
63 | the concepts of ``owning thread'' and ``recursion level'' in | |
64 | addition to the locked/unlocked state used by primitive locks. In | |
65 | the locked state, some thread owns the lock; in the unlocked | |
66 | state, no thread owns it. | |
67 | ||
68 | <P> | |
69 | To lock the lock, a thread calls its <tt class="method">acquire()</tt> method; this | |
70 | returns once the thread owns the lock. To unlock the lock, a | |
71 | thread calls its <tt class="method">release()</tt> method. | |
72 | <tt class="method">acquire()</tt>/<tt class="method">release()</tt> call pairs may be nested; only | |
73 | the final <tt class="method">release()</tt> (the <tt class="method">release()</tt> of the outermost | |
74 | pair) resets the lock to unlocked and allows another thread blocked in | |
75 | <tt class="method">acquire()</tt> to proceed. | |
76 | ||
77 | <P> | |
78 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
79 | <td><nobr><b><tt id='l2h-2722' xml:id='l2h-2722' class="method">acquire</tt></b>(</nobr></td> | |
80 | <td><var></var><big>[</big><var>blocking<code> = 1</code></var><big>]</big><var></var>)</td></tr></table></dt> | |
81 | <dd> | |
82 | Acquire a lock, blocking or non-blocking. | |
83 | ||
84 | <P> | |
85 | When invoked without arguments: if this thread already owns | |
86 | the lock, increment the recursion level by one, and return | |
87 | immediately. Otherwise, if another thread owns the lock, | |
88 | block until the lock is unlocked. Once the lock is unlocked | |
89 | (not owned by any thread), then grab ownership, set the | |
90 | recursion level to one, and return. If more than one thread | |
91 | is blocked waiting until the lock is unlocked, only one at a | |
92 | time will be able to grab ownership of the lock. There is no | |
93 | return value in this case. | |
94 | ||
95 | <P> | |
96 | When invoked with the <var>blocking</var> argument set to true, do the | |
97 | same thing as when called without arguments, and return true. | |
98 | ||
99 | <P> | |
100 | When invoked with the <var>blocking</var> argument set to false, do not | |
101 | block. If a call without an argument would block, return false | |
102 | immediately; otherwise, do the same thing as when called | |
103 | without arguments, and return true. | |
104 | </dl> | |
105 | ||
106 | <P> | |
107 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
108 | <td><nobr><b><tt id='l2h-2723' xml:id='l2h-2723' class="method">release</tt></b>(</nobr></td> | |
109 | <td><var></var>)</td></tr></table></dt> | |
110 | <dd> | |
111 | Release a lock, decrementing the recursion level. If after the | |
112 | decrement it is zero, reset the lock to unlocked (not owned by any | |
113 | thread), and if any other threads are blocked waiting for the lock to | |
114 | become unlocked, allow exactly one of them to proceed. If after the | |
115 | decrement the recursion level is still nonzero, the lock remains | |
116 | locked and owned by the calling thread. | |
117 | ||
118 | <P> | |
119 | Only call this method when the calling thread owns the lock. | |
120 | Do not call this method when the lock is unlocked. | |
121 | ||
122 | <P> | |
123 | There is no return value. | |
124 | </dl> | |
125 | ||
126 | <P> | |
127 | ||
128 | <DIV CLASS="navigation"> | |
129 | <div class='online-navigation'> | |
130 | <p></p><hr /> | |
131 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
132 | <tr> | |
133 | <td class='online-navigation'><a rel="prev" title="7.5.1 Lock Objects" | |
134 | href="lock-objects.html"><img src='../icons/previous.png' | |
135 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
136 | <td class='online-navigation'><a rel="parent" title="7.5 threading " | |
137 | href="module-threading.html"><img src='../icons/up.png' | |
138 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
139 | <td class='online-navigation'><a rel="next" title="7.5.3 Condition Objects" | |
140 | href="condition-objects.html"><img src='../icons/next.png' | |
141 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
142 | <td align="center" width="100%">Python Library Reference</td> | |
143 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
144 | href="contents.html"><img src='../icons/contents.png' | |
145 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
146 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
147 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
148 | <td class='online-navigation'><a rel="index" title="Index" | |
149 | href="genindex.html"><img src='../icons/index.png' | |
150 | border='0' height='32' alt='Index' width='32' /></A></td> | |
151 | </tr></table> | |
152 | <div class='online-navigation'> | |
153 | <b class="navlabel">Previous:</b> | |
154 | <a class="sectref" rel="prev" href="lock-objects.html">7.5.1 Lock Objects</A> | |
155 | <b class="navlabel">Up:</b> | |
156 | <a class="sectref" rel="parent" href="module-threading.html">7.5 threading </A> | |
157 | <b class="navlabel">Next:</b> | |
158 | <a class="sectref" rel="next" href="condition-objects.html">7.5.3 Condition Objects</A> | |
159 | </div> | |
160 | </div> | |
161 | <hr /> | |
162 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
163 | </DIV> | |
164 | <!--End of Navigation Panel--> | |
165 | <ADDRESS> | |
166 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
167 | </ADDRESS> | |
168 | </BODY> | |
169 | </HTML> |