Re: [HACKERS] Is libpq re-entrant? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Is libpq re-entrant?
Date
Msg-id 20155.917895619@sss.pgh.pa.us
Whole thread Raw
In response to Is libpq re-entrant?  (Ian Grant <I.A.N.Grant@damtp.cam.ac.uk>)
List pgsql-hackers
Ian Grant <I.A.N.Grant@damtp.cam.ac.uk> writes:
> Can anyone confirm for me that libpq is re-entrant. Ie, it is safe to
> execute libpq calls from within a signal handler when that signal could've
> interrupted a libpq function? Of course I don't expect to be able to use
> the same PGconn or PGresult structures inside the signal handler as
> outside.

Operations on a single PGconn are definitely not thread-safe, but I
think you could use multiple PGconns from different threads without
trouble.  The only gotcha I know of offhand is that PQconnectdb()
is not thread-safe because of use of a modifiable static data structure.
Fixing that seems to require changing the API, so I haven't done
anything about it yet.

Of course this assumes that your underlying libc is thread-safe;
if malloc(), sprintf(), et al are not thread-safe then better
forget the whole thing.

There is a special exception for PQrequestCancel, which is supposed
to be safely callable from a signal handler even if your libc is
brain-dead.

If you try it and find any other problems let me know; I'll see if
I can do anything about them.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Venkatesh. K"
Date:
Subject: ...
Next
From: jwieck@debis.com (Jan Wieck)
Date:
Subject: Re: [HACKERS] Re: [COMMITTERS] [WEBMASTER] 'www/html main.html'