my $default= {
stackBytes => 4*1024,
...,
};
sub getDefault {
return $default;
}
sub new {
my $us= shift @_;
my $opts= shift @_;
if( $opts && ! isa($opts,"HASH") ) {
$opts= {
code => $opts,
args => \@_,
};
}
my $class= ref($us) || $us;
my $proto= ref($us) ? $us : $class->getDefault();
my $self= bless { }, $class;
my @configKeys= keys %{ $class->getDefault() };
# add error checking to taste here,
# but this conveys the idea
@$self{ @configKeys }= @$proto{ @configKeys };
@$self{ keys %$opts }= values %$opts;
return $self;
}
####
my $threads= threads->new( {
stackBytes => 16*1024, # default
...
} );
...
my $worker= $threads->create( ... );
my $deep= $threads->create(
{ stackBytes => 32*1024 },
...,
);
$threads->setStackBytes( ... );
my @hive= map $threads->create( ... ), ...;
####
my $threadFactory= use threads;
####
require threads;
...
my $child= threads->create( \&mySsub );
####
require threads;
my $threads= threads->new( {
stackBytes => ...,
} );
####
use threads(
Factory => \my $threads,
StackBytes => ...,
);