| PostgreSQL 9.0.4 中文文档 | ||||
|---|---|---|---|---|
| Prev | Fast Backward | Chapter 31. libpq-C库 | Fast Forward | Next |
libpq是可重入的并且是线程安全的。另外,在你编译自己的应用代码时, 可能需要使用额外的编译器命令行选项。请参考你的系统的文档获取有关如何 编译多线程应用的信息。或者查阅src/Makefile.global, 找PTHREAD_CFLAGS和PTHREAD_LIBS。此功能允许查询 的libpq的线程安全状态:
一个现实是,两个线程不能试图同时操作同一个PGconn对象。特别是, 你不能从不同的线程里通过同一个连接对象发出并发的命令。 (如果你需要运行并行命令,请使用多个连接。)
PGresult对象在创建后是只读的,因此可以自由地在线程之间传递。
过时了的函数PQrequestCancel和PQoidStatus都是线程不安全的,
因此不应该在一个多线程的程序里面使用。PQrequestCancel可以由PQcancel代替。
PQoidStatus可以由PQoidValue代替。
If you are using Kerberos inside your application (in addition to inside
libpq),you will need to do locking around
Kerberos calls because Kerberos functions are not thread-safe. See
functionPQregisterThreadLockin the
libpqsource code for a way to do cooperative
locking betweenlibpqand your application.
如果在你的应用内部使用了 Kerberos (而不仅仅是libpq里面),
你就需要在 Kerberos 调用周围锁住,因为 Kerberos 函数不是线程安全的。
参阅libpq源代码里面的PQregisterThreadLock获取一个
在libpq和你的应用之间进行恰当锁定的方法。
If you experience problems with threaded applications,run the program insrc/tools/threadto see if your platform has thread-unsafe functions. This program is run by configure,but for binary distributions your library might not match the library used to build the binaries. 如果你的线程应用有问题,那么运行一个在src/tools/thread里的程序, 看看你的平台是否有线程安全的函数。这个程序由configure运行,但如果是二进制版本, 你的库可能就不能和制作二进制的那个库匹配了。