pg.ddx.io pgsql-interfaces@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Using libpq in a multithreaded environment 2+ messages / 2 participants [nested] [flat]
* Using libpq in a multithreaded environment @ 2000-02-25 16:47 Rini Dutta <rinid@rocketmail.com> 2000-02-25 18:19 ` Re: [HACKERS] Using libpq in a multithreaded environment Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: Rini Dutta @ 2000-02-25 16:47 UTC (permalink / raw) To: pgsql-interfaces; +Cc: pgsql-hackers@postgresql.org Hi, 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. 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. Could you tell me if there is a way to use one connection in multiple threads, or whether I will need to necessarily open one Connection per thread ? Which is the preferred course of action ? Thanks, Rini ps : Sorry, but I've been unable to search the archives before sending this mail. For the last three days each time I try a search I get the folllowing message : The document contained no data. Try again later or contact the server's administrator. __________________________________________________ Do You Yahoo!? Talk to your friends online with Yahoo! Messenger. http://im.yahoo.com ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [HACKERS] Using libpq in a multithreaded environment 2000-02-25 16:47 Using libpq in a multithreaded environment Rini Dutta <rinid@rocketmail.com> @ 2000-02-25 18:19 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2000-02-25 18:19 UTC (permalink / raw) To: Rini Dutta <rinid@rocketmail.com>; +Cc: pgsql-interfaces; pgsql-hackers@postgreSQL.org 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 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-02-25 18:19 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2000-02-25 16:47 Using libpq in a multithreaded environment Rini Dutta <rinid@rocketmail.com> 2000-02-25 18:19 ` Tom Lane <tgl@sss.pgh.pa.us>
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