Perrin Harkins wrote:
> Elizabeth Mattijsen wrote:
>
>> Hmm... but you won't be able to "fetch" the $dbh from the thread. It
>> can only live in _that_ thread. You cannot "pass" objects between
>> threads. But you _can_ send queries to that thread, fetch a jobid for
>> that job and then obtain whatever was returned as a Perl datastructure.
>>
>> (if anyone knows of a way to pass objects between threads, I'd really
>> would like to know)
>
>
> Hmmm... That could really throw a wrench in things. If you have an
> object based on a hash, and you share that hash, and you re-bless the
> object in each thread, does that work? What if the hash contains
> references to other variables. Do they need to be explicity shared as
> well?
That's what I meant. Probably non need for Thread::Pool, at all. use a
shared datastructure, maintain a list of free and busy items and simply
hand pointers inside this datastructure to the threads asking for an
item. e.g.:
package DBI::Pool;
use threads::shared;
my @pool : shared;
sub init {} # pre-populate pool with N connections
sub get {} # return a ref to $dbh, grow the pool if needed
sub put {} # move the pointer from the busy list to the free list
won't this work? I guess Perrin is right in respect that the whole item
needs to be shared (deep-shared). can we have such an attribute/function
that will automatically traverse the datastructure and share it all? or
is this the case already with 'shared'?
Now since we want to have various connections, it can be:
my %pools : shared;
where each key is a unique identifier, "compiled" from the dbi connect's
DSN string and a value is the actual pool.
BTW, there is no more need for Apache prefix in Apache::DBI, this can be
a generic Pool class. I guess Apache::DBI can subclass DBI::Pool and add
things like connect_on_init(), but just to build the initial pool when
the process starts.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com