gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
5.5KB

  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"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>33.19. Behavior in Threaded Programs</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="libpq-ssl.html" title="33.18. SSL Support" /><link rel="next" href="libpq-build.html" title="33.20. Building libpq Programs" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">33.19. Behavior in Threaded Programs</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="libpq-ssl.html" title="33.18. SSL Support">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="libpq.html" title="Chapter 33. libpq - C Library">Up</a></td><th width="60%" align="center">Chapter 33. <span xmlns="http://www.w3.org/1999/xhtml" class="application">libpq</span> - C Library</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="libpq-build.html" title="33.20. Building libpq Programs">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="LIBPQ-THREADING"><div class="titlepage"><div><div><h2 class="title" style="clear: both">33.19. Behavior in Threaded Programs</h2></div></div></div><a id="id-1.7.3.26.2" class="indexterm"></a><p>
  3. <span class="application">libpq</span> is reentrant and thread-safe by default.
  4. You might need to use special compiler command-line
  5. options when you compile your application code. Refer to your
  6. system's documentation for information about how to build
  7. thread-enabled applications, or look in
  8. <code class="filename">src/Makefile.global</code> for <code class="literal">PTHREAD_CFLAGS</code>
  9. and <code class="literal">PTHREAD_LIBS</code>. This function allows the querying of
  10. <span class="application">libpq</span>'s thread-safe status:
  11. </p><div class="variablelist"><dl class="variablelist"><dt id="LIBPQ-PQISTHREADSAFE"><span class="term">
  12. <code class="function">PQisthreadsafe</code>
  13. <a id="id-1.7.3.26.4.1.1.2" class="indexterm"></a>
  14. </span></dt><dd><p>
  15. Returns the thread safety status of the
  16. <span class="application">libpq</span> library.
  17. </p><pre class="synopsis">
  18. int PQisthreadsafe();
  19. </pre><p>
  20. </p><p>
  21. Returns 1 if the <span class="application">libpq</span> is thread-safe
  22. and 0 if it is not.
  23. </p></dd></dl></div><p>
  24. One thread restriction is that no two threads attempt to manipulate
  25. the same <code class="structname">PGconn</code> object at the same time. In particular,
  26. you cannot issue concurrent commands from different threads through
  27. the same connection object. (If you need to run concurrent commands,
  28. use multiple connections.)
  29. </p><p>
  30. <code class="structname">PGresult</code> objects are normally read-only after creation,
  31. and so can be passed around freely between threads. However, if you use
  32. any of the <code class="structname">PGresult</code>-modifying functions described in
  33. <a class="xref" href="libpq-misc.html" title="33.11. Miscellaneous Functions">Section 33.11</a> or <a class="xref" href="libpq-events.html" title="33.13. Event System">Section 33.13</a>, it's up
  34. to you to avoid concurrent operations on the same <code class="structname">PGresult</code>,
  35. too.
  36. </p><p>
  37. The deprecated functions <code class="function">PQrequestCancel</code> and
  38. <code class="function">PQoidStatus</code> are not thread-safe and should not be
  39. used in multithread programs. <code class="function">PQrequestCancel</code>
  40. can be replaced by <code class="function">PQcancel</code>.
  41. <code class="function">PQoidStatus</code> can be replaced by
  42. <code class="function">PQoidValue</code>.
  43. </p><p>
  44. If you are using Kerberos inside your application (in addition to inside
  45. <span class="application">libpq</span>), you will need to do locking around
  46. Kerberos calls because Kerberos functions are not thread-safe. See
  47. function <code class="function">PQregisterThreadLock</code> in the
  48. <span class="application">libpq</span> source code for a way to do cooperative
  49. locking between <span class="application">libpq</span> and your application.
  50. </p><p>
  51. If you experience problems with threaded applications, run the program
  52. in <code class="filename">src/tools/thread</code> to see if your platform has
  53. thread-unsafe functions. This program is run by
  54. <code class="filename">configure</code>, but for binary distributions your
  55. library might not match the library used to build the binaries.
  56. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="libpq-ssl.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="libpq.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="libpq-build.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">33.18. SSL Support </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 33.20. Building <span class="application">libpq</span> Programs</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1