in reply to Re^2: threads: spawn early to avoid the crush.
in thread threads: spawn early to avoid the crush.

I like this idea. A suggestion for the interface:

use threads::lite; my $factory = threads::line->new( -threads => 10 ); #reserve 10 thread +s my $x_thr = $factory->create( \&doX, \@Xargs, \%optional_configs ); my $y_thr = $factory->create( \&doY, \@Yargs );

The general ideas are

  1. Spawn a number of threads up-front, if you use more, they are spawned as needed. When the factory is created, the threads could run something like:
    sub _default_thread { my $thr_id = shift; if (defined $s_coderef[$thr_id] && ref $s_coderef[$thr_id] eq 'CODE +') { $s_coderef[$thr_id]->(@{ $s_param[$thr_id] }); $s_coderef[$thr_id] = undef; } else { sleep(1) } }
  2. Pass arguments as single ARRAYref, opening the door for per-thread configuration.

This is just off the top of my head, so take it as such.

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet