perl thread
1 #!/usr/local/bin/perl2 use threads;
3
4 @domain = ("tom.com", "chinadns.com", "163.com", "aol.com");
5 for ($i=0;$i<4;$i++)
6 {
7 print $i.'.'.$domain[$i].' ';
8 }
9 print "\n";
10
11 my $thr0 = threads->new(\&checkwhois, '0', $domain);
12 my $thr1 = threads->new(\&checkwhois, '1', $domain);
13 my $thr2 = threads->new(\&checkwhois, '2', $domain);
14 my $thr3 = threads->new(\&checkwhois, '3', $domain);
15
16 sub checkwhois()
17 {
18 my ($l,$r)=@_;
19 my $i=0;
20 while($i<1000000)
21 {
22 $i*$i;
23 $i++;
24 }
25 print "done--$l\t\n";
26 print $l.$r." query successful! \n";
27 }
28
29 $thr0->join;
30 $thr1->join;
31 $thr2->join;
32 $thr3->join;
页:
[1]