How to issure PQexec is thread safety if use a connceion in two threads?

From: "Fly(dot)Li" <fly2nn(at)126(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: How to issure PQexec is thread safety if use a connceion in two threads?
Date: 2009-05-21 04:04:27
Message-ID: gv2jse$20b8$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, all

Reading libpq code( PQexec() ), I cann't find measure for thread safety.

Read libpq doc, there are some words:
---------------------
One thread restriction is that no two threads attempt to manipulate the same
PGconn 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.)
-------------------------------

I dont't think it is a good idea. Should libpq do something for issure the
true thread safety?

ODBC specilization said:
---------------------------
On multithread operating systems, drivers must be thread-safe. That is, it
must be possible for applications to use the same handle on more than one
thread. How this is achieved is driver-specific, and it is likely that
drivers will serialize any attempts to concurrently use the same handle on
two different threads.

Applications commonly use multiple threads instead of asynchronous
processing. The application creates a separate thread, calls an ODBC
function on it, and then continues processing on the main thread. Rather
than having to continually poll the asynchronous function, as is the case
when the SQL_ATTR_ASYNC_ENABLE statement attribute is used, the application
can simply let the newly created thread finish.

Functions that accept a statement handle and are running on one thread can
be canceled by calling SQLCancel with the same statement handle from another
thread. Although drivers should not serialize the use of SQLCancel in this
manner, there is no guarantee that calling SQLCancel will actually cancel
the function running on the other thread.

Any ideas?

thanks

regards
Fly.Li

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2009-05-21 04:10:21 pull raw text of a message by message-id
Previous Message Robert Haas 2009-05-21 03:40:31 from_collapse_limit vs. geqo_threshold