[Zope-dev] Making a ZSQL.DA fully multi-threaded?

Andy Dustman farcepest at gmail.com
Fri Jul 16 11:38:14 EDT 2004


On Fri, 16 Jul 2004 10:36:27 -0400, Brad Clements <bkc at murkworks.com> wrote:

> The SAP  folks say their adapter is "multi-thread capable", but I've come to believe that only
> means that it's ok to open a connection in one thread and use it in another, but NOT to have
> 2 threads make requests on the same connection at the same time.

I would be surprised to find any database API that allowed that.
Generally "thread-safe" means that there are no global state
variables, i.e. all connection state is encapsulated in the connection
object/struct. Generally I would not try to share connections between
threads at all. To do it, you'd need to ensure that a thread performs
a commit or rollback on the connection before another thread can use
it, i.e. performs a complete transaction or none at all. Otherwise you
will have all sorts of interesting problems.

> Also, two threads can' t open a connection "at the same time" because their connection table
> management isn't "thread safe".

That does suck, but it doesn't seem like an insurmountable problem for
a DA. You just need a per-DA instance mutex which you acquire before
opening a connection release afterwards.


More information about the Zope-Dev mailing list