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