Thread: Multithreading

Multithreading

From
Leandro Fanzone
Date:
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,

Leandro Fanzone
Compañía HASAR


Re: Multithreading

From
Warwick Hunter
Date:
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