- 论坛徽章:
- 0
|
回复 #31 MMMIX 的帖子
对的,以前也是这么设计的,但是得到这个错误:Can't locate object method "is_joinable" via package "threads" at thread1.pl.bak line 23.
perl的版本是,
bash-3.2# perl -v
This is perl, v5.8.8 built for PA-RISC1.1-thread-multi
(with 26 registered patches, see perl -V for more detail)
Copyright 1987-2006, Larry Wall
Binary build 817 [257965] provided by ActiveState http://www.ActiveState.com
Built Mar 20 2006 19:44:08
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
#!/usr/bin/perl
use threads;
use strict;
use Data:umper;
sub prt(){
`echo "$_[0]" >> t.txt`;
}
my $current_thread;
my %thrs = ();
for(1..300)
{
$current_thread = scalar (keys %thrs);
if( $current_thread < 10 )
{
$thrs{$_} = threads->create(\&prt,$_);
}else{
print "more than 10 threads\n";
print Dumper \%thrs;
foreach my $t (keys %thrs){
if($thrs{$t}->is_joinable()){
$thrs{$t}->join();
delete $thrs{$t};
}
}
$thrs{$_} = threads->create(\&prt,$_);
}
}
foreach my $t (keys %thrs){
$thrs{$t}->join();
delete $thrs{$t};
}
print Dumper \%thrs; |
|