Having said that, why aren't you being more general? You have a subroutine for each thread that does the same thing:
You should generalize that. Something like this untested piece of code:sub australianNationalUniversity { use AustralianNationalUniversity; AustralianNationalUniversity::search( $maxHits, %searchTerms ); my @results = AustralianNationalUniversity::getResults(); lock(@searchResults); push ( @searchResults, @results ); }
Also, why hold each thread in a seperate variable? Why not store them in an array instead? Because you have 13 seperate search items? Nonesense! Just "tag" them with a leading underscore (or whatever) so you can grep them out of CGI::param() like so:# at the beginning of your code: use GenericSearch; # and then just ONE sub for all threads sub get_search { my $group = shift; GenericSearch::search($group, $maxHits, %searchTerms ); my @results = GenericSearch::getResults(); lock(@searchResults); push ( @searchResults, @results ); }
Code smart, not hard. ;)my @search = grep /^_/, param(); # now remove the underscores $_ = substr($_,1) for @search; # now create the threads; my @thread = map { threads->new(sub {get_search($_)})}, @search; # and finally, join them when done $_->join for @thread;
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Re: Question about threads
by jeffa
in thread Question about threads
by Gwalchmai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |