#!/usr/bin/perl -w use threads; sub function{ my @args = @_; #print "function\n",@args,"\n"; #sleep int(rand(4)); #sleep 1; #select( undef,undef,undef,0.25 ); my $a = $args[0]; my $b = 0; for ( 1..($a*1000) ){ $b++; $b = $b/10; $b++; $b *= 10; $b = $b / ($a+1); $b = $b /1.2334645897; $b = $b * 234.2312125; $b = $b/$a; $b++; $b = $b * $a; } return ( $a + 100 ); } my @threads; for my $a ( 1..10 ){ push @threads, threads->create( "function", $a ); } for my $a ( 10..300 ){ push @threads, threads->create( "function", $a ); my $t = shift @threads; $t->join(); } $_->join for @threads;