From: Tom Lane <tgl@sss.pgh.pa.us>
To: Rini Dutta <rinid@rocketmail.com>
Cc: pgsql-interfaces@postgreSQL.org
Cc: pgsql-hackers@postgreSQL.org
Subject: Re: [HACKERS] Using libpq in a multithreaded environment
Date: Fri, 25 Feb 2000 13:19:34 -0500
Message-ID: <7802.951502774@sss.pgh.pa.us> (raw)
In-Reply-To: <20000225164731.18954.qmail@web2903.mail.yahoo.com>
References: <20000225164731.18954.qmail@web2903.mail.yahoo.com>
Rini Dutta <rinid@rocketmail.com> writes:
> I need to use libpq in a multithreaded environment.
> Ideally I would like to open a single connection to
> the database and use that for all threads.
Not unless you provide some interlock that will prevent multiple threads
from issuing queries at the same time...
> I just discovered that the PGconn returned when a
> connection is opened is usable for only one thread
> since it also seems to store the result (PGresult *)
> and the errorMessage.
This is the least of your worries --- the backend is not multithreaded
either, so it will not accept concurrent queries; nor is the frontend-
to-backend protocol capable of keeping track of concurrent queries.
Unless your intended use of the connection is considerably more
restricted than you have indicated, you will want one connection
per query-issuing thread.
This would not prevent you from handing off completed PGresults to
other threads for processing; but operations on a PGconn should be
either restricted to one thread or protected by a mutex.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: tgl@sss.pgh.pa.us, rinid@rocketmail.com, pgsql-hackers@postgreSQL.org
Subject: Re: [HACKERS] Using libpq in a multithreaded environment
In-Reply-To: <7802.951502774@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox