Re: Multithreading - Mailing list pgsql-novice

From Warwick Hunter
Subject Re: Multithreading
Date
Msg-id 3CC746AC.9010404@oz.agile.tv
Whole thread Raw
In response to Multithreading  (Leandro Fanzone <leandro@hasar.com>)
List pgsql-novice
Leandro

> I'm using the libpq++ library to access PostgreSQL 7, and I need to use
> it from several threads at the same time. Is that supported, id est,
> does it have serialization mechanisms or do I have to mutex it myself?
> Thank you in advance,

[From the doco for 7.2]

1.11. Threading Behavior

libpq is thread-safe as of PostgreSQL 7.0, so long as no two threads
attempt to manipulate the same PGconn object at the same time. In
particular, you cannot issue concurrent queries from different threads
through the same connection object. (If you need to run concurrent
queries, start up multiple connections.)

[...]

I have done this with the libpq interface and I create a connection
per thread and store the pointer to the connection object in
thread specific storage. This means no two threads will access the
same connection.

I am actually using C++ and chose the C interface because the parts
of the C++ interface I was using were a bit hard to use. I implement
the thread local storage by using a class ACE_TSS from the ACE
library with makes thread specific storage really easy
http://www.cs.wustl.edu/~schmidt/ACE.html

Warwick
--
Warwick Hunter                    Agile TV Corporation
Voice: +61 7 5584 5912            Fax: +61 7 5575 9550
mailto:whunter@oz.agile.tv        http://www.agile.tv


pgsql-novice by date:

Previous
From: Andrew McMillan
Date:
Subject: Re: performance problems with subselects
Next
From: "Henshall, Stuart - WCP"
Date:
Subject: Re: support for atomic multi-table updates?