> I don't understand why 10 threads each with their own DB connection
> works, yet a connection made by MAIN in the perl script stops any
> threads from making a new connection ? The fact that I can spawn
> 10 threads with their own DB connection means surely that it
> *does* support CLONE ? or am i not understanding the underlying
> principles correctly ?

i have an application which uses 25-30 threads in addition to the main
thread, all of which (including the main thread) maintain their own db
connection successfully.  the difference may be that i don't open the main
thread's db handle until *after* i spawn the threads - my app is built to
use a thread pool and not start up any new threads after the initial set.
not sure if that would work for you, but try moving the db connect call to
after your threads are spawned - in my experience that should work.

my understanding of the internals (which is limited at best) is that there
are two ways a module/package needs to be CLONE-able: the compiled module
needs to be functional when it is duplicated for each new thread, and
instances of the package it defines need to be functional when copied to
each new thread's memory.  DBD::mysql seems ok with the first and not the
second - you should be able to instantiate a db handle in your spawned
threads, but you can't let perl copy actual db handles or it'll choke.  if
anyone else has a better/more accurate explanation than that, please let me
know.

jack


Reply via email to