Thread: Multi-threaded client apps

Multi-threaded client apps

From
"Gunkel, Marc B"
Date:
Are client connections to the database thread-safe?  Can each client thread
have its own connection?

What happens if multiple threads share one connection? For instance, can one
thread open a connection and another thread close it?
I realize this is probably not a good idea for many reasons, but our
architecture is dictating it.

Marc Gunkel
mgunke@sandia.gov
505-844-3395



Re: Multi-threaded client apps

From
Tom Lane
Date:
"Gunkel, Marc B" <mgunke@sandia.gov> writes:
> Can each client thread have its own connection?

That should work.

> What happens if multiple threads share one connection? For instance, can one
> thread open a connection and another thread close it?

Not a good idea unless you provide a mutex to ensure that only one
thread manipulates the PGconn object at a time.

Basically, libpq is thread-safe (in recent releases) but not thread-aware.

            regards, tom lane

RE: Multi-threaded client apps

From
"JGL"
Date:

-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Tom Lane
Sent: Monday, February 12, 2001 4:20 PM
To: Gunkel, Marc B
Cc: 'pgsql-novice@postgresql.org'
Subject: Re: [NOVICE] Multi-threaded client apps


"Gunkel, Marc B" <mgunke@sandia.gov> writes:
> Can each client thread have its own connection?

That should work.

> What happens if multiple threads share one connection? For instance, can
one
> thread open a connection and another thread close it?

Not a good idea unless you provide a mutex to ensure that only one
thread manipulates the PGconn object at a time.

Basically, libpq is thread-safe (in recent releases) but not thread-aware.

            regards, tom lane