As of version 17, <application>libpq</application> is always reentrant and thread-safe.
However, one restriction is that no two threads attempt to manipulate
the same <structname>PGconn</structname> 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.)
バージョン17では、libpqは常に再入可能でスレッドセーフです。
ただし、1つの制限として、2つのスレッドが同じPGconn
オブジェクトを同時に操作することはできません。
特に、異なるスレッドから同じ接続オブジェクトを介して同時にコマンドを実行することはできません。(並行してコマンドを実行する必要がある場合は、複数の接続を使用してください。)
<structname>PGresult</structname> objects are normally read-only after creation,
and so can be passed around freely between threads. However, if you use
any of the <structname>PGresult</structname>-modifying functions described in
<xref linkend="libpq-misc"/> or <xref linkend="libpq-events"/>, it's up
to you to avoid concurrent operations on the same <structname>PGresult</structname>,
too.
PGresult
オブジェクトは生成後、読み込み専用であり、そのためスレッド間で自由に渡すことができます。
しかし32.12や32.14で説明するPGresult
を変更する関数のいずれかを使用している場合、同一のPGresult
に対する同時操作を防ぐことも、作成者の責任です。
In earlier versions, <application>libpq</application> could be compiled with or without thread support, depending on compiler options. This function allows the querying of <application>libpq</application>'s thread-safe status: 以前のバージョンでは、libpqはコンパイラオプションに応じてスレッドサポート付きでコンパイルすることも、スレッドサポートなしでコンパイルすることもできました。 この関数はlibpqのスレッドセーフステータスを照会することができます。
PQisthreadsafe
#Returns the thread safety status of the <application>libpq</application> library. libpqライブラリのスレッドセーフ状態を返します。
int PQisthreadsafe();
Returns 1 if the <application>libpq</application> is thread-safe and 0 if it is not. Always returns 1 on version 17 and above. libpqがスレッドセーフである場合は1を、そうでない場合は0を返します。 バージョン17以降では常に1を返します。
The deprecated functions <xref linkend="libpq-PQrequestCancel"/> and
<xref linkend="libpq-PQoidStatus"/> are not thread-safe and should not be
used in multithread programs. <xref linkend="libpq-PQrequestCancel"/>
can be replaced by <xref linkend="libpq-PQcancelBlocking"/>.
<xref linkend="libpq-PQoidStatus"/> can be replaced by
<xref linkend="libpq-PQoidValue"/>.
非推奨の関数、PQrequestCancel
やPQoidStatus
はスレッドセーフではありませんので、マルチスレッドプログラムでは使用してはなりません。
PQrequestCancel
はPQcancelBlocking
に置き換えられます。
PQoidStatus
はPQoidValue
に置き換えられます。
If you are using Kerberos inside your application (in addition to inside
<application>libpq</application>), you will need to do locking around
Kerberos calls because Kerberos functions are not thread-safe. See
function <function>PQregisterThreadLock</function> in the
<application>libpq</application> source code for a way to do cooperative
locking between <application>libpq</application> and your application.
(libpqの内部に加えて)アプリケーション中でKerberosを利用している場合、Kerberos関数はスレッドセーフではありませんのでKerberos呼び出しの前後をロックする必要があるでしょう。
libpqとアプリケーション間のロック処理を協調させる方法としてlibpqのソースコードのPQregisterThreadLock
関数を参照してください。