use strict; use threads; use threads::shared; use Thread::Queue; my $maxnoofThreads = 1; my @clientList = qw(client1 client2 client3 client4 client5 client6 client7 client8 client9 client10 client11 client12); my %hash; my $q = new Thread::Queue; $q->enqueue(@clientList); for(my $i=0;$i<= $maxnoofThreads; $i++) { $hash{$i} = threads->new( \&worker, $q,$i); } $q->enqueue("undef"); foreach my $thr (values %hash) { # Don't join the main thread or ourselves #if ($thr->tid && !threads::equal($thr, threads->self)) # { $thr->join; # } } sub worker { my( $Q ) = shift; my $i = shift; while( my $workItem = $Q->dequeue ) { return unless($workItem); print " workitem from thread $i -->$workItem\n"; ## Perform query ## Perform comparison ## Perform output/cleanup } }