Re: multiple threads using one connection

Поиск
Список
Период
Сортировка
От Philip Yarra
Тема Re: multiple threads using one connection
Дата
Msg-id 200603011118.14079.philip@utiba.com
обсуждение исходный текст
Ответ на Re: multiple threads using one connection  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-interfaces
On Wed, 1 Mar 2006 05:17 am, Bruce Momjian wrote:
> Just to clarify, libpq is thread-safe is each thread uses its own
> connection object.

Hope it's okay if I clarify this a little further, Bruce...

Robert, I think you *should* be able to use the same connection from multiple 
threads so long as you do your own work to avoid concurrent use of the 
connection. I'm sorry, I know less than nothing about Ada, but in C terms 
you'd be using a mutex, acquiring it before your thread issues a statement on 
the connection, reading back all data etc., then releasing the mutex. Other 
threads can then acquire the mutex and use the connection. I assume Ada 
provides some similar sort of concurrency control.

On a side note, the preferred way is to use a connection per thread... and 
given the overhead of thread creation, ISTM the cost of a connection wouldn't 
be that high... but I assume you have some good reason for doing it this way. 
I suppose a connection pool might be another way you could handle this 
requirement.

I say it *should* work because I know this works with ECPG, and AFAIK it uses 
libpq calls, so should be similar for your language binding, but please test 
it with a sample app before assuming that I know what I'm talking about. Can 
someone correct me if I have this wrong? It's been a while since I had to 
think about this stuff...

Regards, Philip.

-- 

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

-----------------
Utiba Pty Ltd 
This message has been scanned for viruses and
dangerous content by Utiba mail server and is 
believed to be clean.



В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: Python psycopg transaction isolation level
Следующее
От: elein
Дата:
Сообщение: plpython