Debian Codegraph @

docs/api_reference/C/envset_thread_id.html

raw symbols SCIP
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>DB_ENV-&gt;set_thread_id()</title>
7 <link rel="stylesheet" href="apiReference.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 C API Reference" />
10 <link rel="up" href="env.html" title="Chapter 5.  The DB_ENV Handle" />
11 <link rel="prev" href="envset_thread_count.html" title="DB_ENV-&gt;set_thread_count()" />
12 <link rel="next" href="envset_thread_id_string.html" title="DB_ENV-&gt;set_thread_id_string()" />
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">DB_ENV-&gt;set_thread_id()</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="envset_thread_count.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 5. 
26 The DB_ENV Handle
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="envset_thread_id_string.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="envset_thread_id"></a>DB_ENV-&gt;set_thread_id()</h2>
38 </div>
39 </div>
40 </div>
41 <pre class="programlisting">#include &lt;db.h&gt;
42
43 int
44 DB_ENV-&gt;set_thread_id(DB_ENV *dbenv,
45 void (*thread_id)(DB_ENV *dbenv, pid_t *pid, db_threadid_t *tid)); </pre>
46 <p>
47 Declare a function that returns a unique identifier pair for the
48 current thread of control. The
49 <code class="methodname">DB_ENV-&gt;set_thread_id()</code> method supports the
50 <a class="xref" href="envfailchk.html" title="DB_ENV-&gt;failchk()">DB_ENV-&gt;failchk()</a> method.
51 For more information, see
52 <a href="../../programmer_reference/cam_app.html" class="olink">
53 Architecting Data Store and Concurrent Data Store applications
54 </a>, and
55 <a href="../../programmer_reference/transapp_app.html" class="olink">
56 Architecting Transactional Data Store applications
57 </a>, both in the
58 <em class="citetitle">Berkeley DB Programmer's Reference Guide</em>.
59 </p>
60 <p>
61 The <code class="methodname">DB_ENV-&gt;set_thread_id()</code> method
62 configures operations performed using the specified
63 <a class="link" href="env.html" title="Chapter 5.  The DB_ENV Handle">DB_ENV</a> handle, not all operations
64 performed on the underlying database environment.
65 </p>
66 <p>
67 The <code class="methodname">DB_ENV-&gt;set_thread_id()</code> method may be
68 called at any time during the life of the application.
69 </p>
70 <p>
71 The <code class="methodname">DB_ENV-&gt;set_thread_id()</code> <span>
72 <span>
73 method returns a non-zero error value on failure and 0 on success.
74 </span>
75
76 </span>
77 </p>
78 <div class="sect2" lang="en" xml:lang="en">
79 <div class="titlepage">
80 <div>
81 <div>
82 <h3 class="title"><a id="idp52236000"></a>Parameters</h3>
83 </div>
84 </div>
85 </div>
86 <div class="sect3" lang="en" xml:lang="en">
87 <div class="titlepage">
88 <div>
89 <div>
90 <h4 class="title"><a id="idp52251824"></a>thread_id</h4>
91 </div>
92 </div>
93 </div>
94 <p>
95 The <span class="bold"><strong>thread_id</strong></span> parameter is a function
96 which returns a unique identifier pair for a thread of control in a
97 Berkeley DB application. The function takes three arguments:
98 </p>
99 <div class="itemizedlist">
100 <ul type="disc">
101 <li>
102 <p>
103 <span class="bold"><strong>dbenv</strong></span>
104 </p>
105 <p>
106 The <span class="bold"><strong>dbenv</strong></span> parameter is the enclosing
107 database environment handle, allowing application access to the
108 application-private fields of that object.
109 </p>
110 </li>
111 <li>
112 <p>
113 <span class="bold"><strong>pid</strong></span>
114 </p>
115 <p>
116 The <span class="bold"><strong>pid</strong></span> points to a memory location of
117 type <code class="literal">pid_t</code>, or NULL. The process ID of the current
118 thread of control may be returned in this memory location, if it is not
119 NULL.
120 </p>
121 </li>
122 <li>
123 <p>
124 <span class="bold"><strong>tid</strong></span>
125 </p>
126 <p>
127 The <span class="bold"><strong>tid</strong></span> points to a memory location of
128 type <code class="literal">db_threadid_t</code>, or NULL. The thread ID of the
129 current thread of control may be returned in this memory location, if it
130 is not NULL.
131 </p>
132 </li>
133 </ul>
134 </div>
135 </div>
136 </div>
137 <div class="sect2" lang="en" xml:lang="en">
138 <div class="titlepage">
139 <div>
140 <div>
141 <h3 class="title"><a id="idp52262232"></a>Errors</h3>
142 </div>
143 </div>
144 </div>
145 <p>
146 The <code class="methodname">DB_ENV-&gt;set_thread_id()</code> <span>
147 <span>
148 method may fail and return one of the following non-zero errors:
149 </span>
150
151 </span>
152 </p>
153 <div class="sect3" lang="en" xml:lang="en">
154 <div class="titlepage">
155 <div>
156 <div>
157 <h4 class="title"><a id="idp52267336"></a>EINVAL</h4>
158 </div>
159 </div>
160 </div>
161 <p>
162 An invalid flag value or parameter was specified.
163 </p>
164 </div>
165 </div>
166 <div class="sect2" lang="en" xml:lang="en">
167 <div class="titlepage">
168 <div>
169 <div>
170 <h3 class="title"><a id="idp52266128"></a>Assigning Thread IDs</h3>
171 </div>
172 </div>
173 </div>
174 <p>
175 The standard system library calls to return process and thread IDs are often sufficient for this
176 purpose (for example, <code class="methodname">getpid()</code> and
177 <code class="methodname">pthread_self()</code> on POSIX systems or GetCurrentThreadID on Windows
178 systems). However, if the Berkeley DB application dynamically creates processes or threads, some
179 care may be necessary in assigning unique IDs. In most threading systems, process and thread IDs are
180 available for re-use as soon as the process or thread exits. If a new process or thread is created
181 between the time of process or thread exit, and the
182 <a class="xref" href="envfailchk.html" title="DB_ENV-&gt;failchk()">DB_ENV-&gt;failchk()</a> method is run, it may be possible for
183 <a class="xref" href="envfailchk.html" title="DB_ENV-&gt;failchk()">DB_ENV-&gt;failchk()</a>
184 to not detect that a thread of control exited without properly
185 releasing all Berkeley DB resources.
186 </p>
187 <p>
188 It may be possible to handle this problem by inhibiting process or thread
189 creation between thread of control exit and calling the
190 <a class="xref" href="envfailchk.html" title="DB_ENV-&gt;failchk()">DB_ENV-&gt;failchk()</a>
191 method. Alternatively, the <span class="bold"><strong>thread_id</strong></span> function
192 must be constructed to not re-use <span class="bold"><strong>pid/tid</strong></span>
193 pairs. For example, in a single process application, the returned process ID
194 might be used as an incremental counter, with the returned thread ID set to the
195 actual thread ID. Obviously, the <span class="bold"><strong>is_alive</strong></span>
196 function specified to the
197 <a class="xref" href="envset_isalive.html" title="DB_ENV-&gt;set_isalive()">DB_ENV-&gt;set_isalive()</a>
198 method must be compatible with any
199 <span class="bold"><strong>thread_id</strong></span> function specified to
200 <code class="methodname">DB_ENV-&gt;set_thread_id()</code>.
201 </p>
202 <p>
203 The db_threadid_t type is configured to be the same type as a standard thread identifier, in
204 Berkeley DB configurations where this type is known (for example, systems supporting pthread_t or
205 thread_t, or DWORD on Windows). If the Berkeley DB configuration process is unable to determine the
206 type of a standard thread identifier, the db_thread_t type is set to uintmax_t (or the largest
207 available unsigned integral type, on systems lacking the uintmax_t type). Applications running on
208 systems lacking a detectable standard thread type, and which are also using thread APIs where a
209 thread identifier is not an integral value and so will not fit into the configured db_threadid_t
210 type, must either translate between the db_threadid_t type and the thread identifier (mapping the
211 thread identifier to a unique identifier of the appropriate size), or modify the Berkeley DB sources
212 to use an appropriate db_threadid_t type. Note: we do not currently know of any systems where this
213 is necessary. If your application has to solve this problem, please contact our support group and
214 let us know.
215 </p>
216 <p>
217 If no <span class="bold"><strong>thread_id</strong></span> function is specified by the
218 application, the Berkeley DB library will identify threads of control by using
219 the <code class="methodname">taskIdSelf()</code> call on VxWorks, the
220 <code class="methodname">getpid()</code> and
221 <code class="methodname">GetCurrentThreadID()</code> calls on Windows, the
222 <code class="methodname">getpid()</code> and <code class="methodname">pthread_self()</code>
223 calls when the Berkeley DB library has been configured for POSIX pthreads or
224 Solaris LWP threads, the <code class="methodname">getpid()</code> and
225 <code class="methodname">thr_self()</code> calls when the Berkeley DB library has been
226 configured for UI threads, and otherwise <code class="methodname">getpid()</code>.
227 </p>
228 </div>
229 <div class="sect2" lang="en" xml:lang="en">
230 <div class="titlepage">
231 <div>
232 <div>
233 <h3 class="title"><a id="idp52264032"></a>Class</h3>
234 </div>
235 </div>
236 </div>
237 <p>
238 <a class="link" href="env.html" title="Chapter 5.  The DB_ENV Handle">DB_ENV</a>
239 </p>
240 </div>
241 <div class="sect2" lang="en" xml:lang="en">
242 <div class="titlepage">
243 <div>
244 <div>
245 <h3 class="title"><a id="idp52270928"></a>See Also</h3>
246 </div>
247 </div>
248 </div>
249 <p>
250 <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a>
251 </p>
252 </div>
253 </div>
254 <div class="navfooter">
255 <hr />
256 <table width="100%" summary="Navigation footer">
257 <tr>
258 <td width="40%" align="left"><a accesskey="p" href="envset_thread_count.html">Prev</a> </td>
259 <td width="20%" align="center">
260 <a accesskey="u" href="env.html">Up</a>
261 </td>
262 <td width="40%" align="right"> <a accesskey="n" href="envset_thread_id_string.html">Next</a></td>
263 </tr>
264 <tr>
265 <td width="40%" align="left" valign="top">DB_ENV-&gt;set_thread_count() </td>
266 <td width="20%" align="center">
267 <a accesskey="h" href="index.html">Home</a>
268 </td>
269 <td width="40%" align="right" valign="top"> DB_ENV-&gt;set_thread_id_string()</td>
270 </tr>
271 </table>
272 </div>
273 </body>
274 </html>