#!/usr/bin/perl-w #Libs use strict; use threads; use threads::shared; my %thr; #Threads controling each node my %thr_up; share (%thr_up); #if thread finished job $thr_up shuould be = 0 SMALL:for (1 .. 1000) { #Find a waiting thread unless ($thr_up{"FREE_HOST"}) { $thr_up{"FREE_HOST"} = 1; #thread working flag $thr{"FREE_HOST"} = threads->create("blast_thread"); sleep(1); my @list = threads->list(); $list[scalar(@list-1)]->join () if (scalar(@list) > 2); foreach my $l (@list) {print "$l\n";} } #Just for my surprise: print $thr{FREE_HOST}->tid, ",$thr{FREE_HOST} \n" if ($thr{FREE_HOST}->tid); } sub blast_thread { $thr_up{FREE_HOST} = 0; print "Server UP\n"; return; } ############################