Thread-Needs - Using Thread::Needs with multiple class methods as threads

Posted on Sat Dec 30 09:44:16 2006 by scunacc
Using Thread::Needs with multiple class methods as threads

Hi,

I have a threaded app where each thread is a method inside a module.

I have several modules that each have different sets of use statements.

I want to be able to use Thread::Needs (or something like it if that's not suitable - I've been playing with Symbol::delete_package to no avail) to unload the modules that are not used by each Class in order to keep the per-thread, per-class overhead down.

I tried to look at an example for Thread::Pool, but, Thread::Needs isn't actually used there - it's in the TODO (:-S) so, I wondered, is there an extant example of this anywhere?

Simply put, I do something like (not complete code here you understand - just fragments):

#... use GetOpt::Long; use Pod::Usage; #... use mod1; use mod2; use mod3; #... for $mod (qw(mod1 mod2 mod3)) { $obj = $mod->new(); for (1..$num_threads) { threads->new($obj -> worker(), $obj); } }

(... where, worker() returns a ref to the actual worker "thread" (method))

and, say, mod1 "only" use's Carp & IO::File, say, and mod2 "only" uses Carp & Sys::Hostname & mod3 "only" uses Carp & DBI & DBD

I don't want GetOpt::Long or Pod::Usage to be in the threads at all, and, obviously, e.g. DBI & DBD not to be in the threads for mod1. etc.

Any ideas?

Kind regards

Derek Jones.

Write a response