<application>libpq</application> is reentrant and thread-safe by default.
You might need to use special 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
<filename>src/Makefile.global</filename> for <literal>PTHREAD_CFLAGS</literal>
and <literal>PTHREAD_LIBS</literal>. This function allows the querying of
<application>libpq</application>'s thread-safe status:
デフォルトでlibpqは再入可能、かつ、スレッドセーフです。
アプリケーションコードをコンパイルする時にコンパイラの特殊なコマンドラインオプションを使う必要があるかもしれません。
スレッドを有効にしたアプリケーションの構築方法についての情報は、使用するシステムの文書を参照してください。
また、PTHREAD_CFLAGS
とPTHREAD_LIBS
に関してsrc/Makefile.global
も一読してください。
以下の関数により、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. libpqがスレッドセーフの場合1が、さもなくば0が返ります。
One thread 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.)
スレッドに関する1つの制限として、異なるスレッドから同時に同一の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
オブジェクトは生成後、読み込み専用であり、そのためスレッド間で自由に渡すことができます。
しかし34.12や34.14で説明するPGresult
を変更する関数のいずれかを使用している場合、同一のPGresult
に対する同時操作を防ぐことも、作成者の責任です。
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-PQcancel"/>.
<xref linkend="libpq-PQoidStatus"/> can be replaced by
<xref linkend="libpq-PQoidValue"/>.
非推奨の関数、PQrequestCancel
やPQoidStatus
はスレッドセーフではありませんので、マルチスレッドプログラムでは使用してはなりません。
PQrequestCancel
はPQcancel
に、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
関数を参照してください。