1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>28.15.Behavior in Threaded Programs</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="libpq.html" title="Chapter28.libpq - C Library">
<link rel="prev" href="libpq-ssl.html" title="28.14.SSL Support">
<link rel="next" href="libpq-build.html" title="28.16.Building libpq Programs">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="libpq-threading"></a>28.15.Behavior in Threaded Programs</h2></div></div></div>
<a name="id686887"></a><p><span class="application">libpq</span> is reentrant and thread-safe if the
<code class="filename">configure</code> command-line option
<code class="literal">--enable-thread-safety</code> was used when the
<span class="productname">PostgreSQL</span> distribution was built. In
addition, you might need to use additional compiler command-line
options when you compile your application code. Refer to your
system's documentation for information about how to build
thread-enabled applications, or look in
<code class="filename">src/Makefile.global</code> for <code class="literal">PTHREAD_CFLAGS</code>
and <code class="literal">PTHREAD_LIBS</code>.</p>
<p>One restriction is that no two threads attempt to manipulate the same
<code class="structname">PGconn</code> object at the same time. In particular, you cannot
issue concurrent commands from different threads through the same
connection object. (If you need to run concurrent commands, use
multiple connections.)</p>
<p><code class="structname">PGresult</code> objects are read-only after creation, and so can be
passed around freely between threads.</p>
<p>The deprecated functions
<code class="function">PQrequestCancel</code> and
<code class="function">PQoidStatus</code>
are not thread-safe and should not be used in multithread programs.
<code class="function">PQrequestCancel</code> can be replaced by
<code class="function">PQcancel</code>.
<code class="function">PQoidStatus</code> can be replaced by
<code class="function">PQoidValue</code>.</p>
<p>If you are using Kerberos inside your application (in addition to inside
<span class="application">libpq</span>), you will need to do locking around
Kerberos calls because Kerberos functions are not thread-safe. See
function <code class="function">PQregisterThreadLock</code> in the
<span class="application">libpq</span> source code for a way to do cooperative
locking between <span class="application">libpq</span> and your application.</p>
<p>If you experience problems with threaded applications, run
the program in <code class="filename">src/tools/thread</code> to see if your
platform has thread-unsafe functions. This program is run
by <code class="filename">configure</code>, but for binary distributions
your library might not match the library used to build the binaries.</p>
</div></body>
</html>
|