Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
34.20. Behavior in Threaded Programs
Prev UpChapter 34. libpq — C LibraryHome Next

34.20. Behavior in Threaded Programs#

libpq 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 insrc/Makefile.global forPTHREAD_CFLAGS andPTHREAD_LIBS. This function allows the querying oflibpq's thread-safe status:

PQisthreadsafe#

Returns the thread safety status of thelibpq library.

int PQisthreadsafe();

Returns 1 if thelibpq is thread-safe and 0 if it is not.

One thread restriction is that no two threads attempt to manipulate the samePGconn 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.)

PGresult objects are normally read-only after creation, and so can be passed around freely between threads. However, if you use any of thePGresult-modifying functions described inSection 34.12 orSection 34.14, it's up to you to avoid concurrent operations on the samePGresult, too.

The deprecated functionsPQrequestCancel andPQoidStatus are not thread-safe and should not be used in multithread programs.PQrequestCancel can be replaced byPQcancel.PQoidStatus can be replaced byPQoidValue.

If you are using Kerberos inside your application (in addition to insidelibpq), you will need to do locking around Kerberos calls because Kerberos functions are not thread-safe. See functionPQregisterThreadLock in thelibpq source code for a way to do cooperative locking betweenlibpq and your application.


Prev Up Next
34.19. SSL Support Home 34.21. Buildinglibpq Programs
pdfepub
Go to PostgreSQL 16
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp