バージョンごとのドキュメント一覧

34.20. スレッド化プログラムの振舞い #

<title>Behavior in Threaded Programs</title>

<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_CFLAGSPTHREAD_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.1234.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"/>. 非推奨の関数、PQrequestCancelPQoidStatusはスレッドセーフではありませんので、マルチスレッドプログラムでは使用してはなりません。 PQrequestCancelPQcancelに、PQoidStatusPQoidValueに置き換えることができます。

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関数を参照してください。