use strict;
use threads;
use threads::shared;
use Thread::Queue;
my @clientList = qw(
client1 client2 client3 client4 client5 client6
);
my @queryList = qw(
query1 query2 query3 query4 query5 query6
);
my $maxnoofQueryThreads = 15;
my $maxnoofCompThreads = 30;
my $globalQ = new Thread::Queue;
my $queryBossID = threads->new(\&queryBoss,$globalQ);
my $compBossID = threads->new(\&compBoss,$globalQ,);
$queryBossID->join;
$compBossID->join;
sub queryBoss
{
my $q = new Thread::Queue;
my $globalQ = shift;
my @queryworkers = map {threads->new( \&queryworker, $
+q,$globalQ);} 1 .. $maxnoofQueryThreads;
$q->enqueue(@queryList);
$q->enqueue( ( undef ) x $maxnoofQueryThreads );
$_->join for @queryworkers;
}
sub compBoss
{
my $globalQ = shift;
my @compworkers = map {threads->new( \&compworker, $globalQ);} 1 ..
+$maxnoofCompThreads;
#$q->enqueue(@queryList);
$globalQ->enqueue( ( undef ) x $maxnoofCompThreads );
$_->join for @compworkers;
}
sub compworker
{
my $globalQ = shift;
my $tid = threads->self->tid;
while(my $workItem = $globalQ->dequeue)
{
print " the file is $workItem \n";
#start comparison on the file and dump result in a new file and de
+l the file
}
}
sub queryworker
{
my( $Q ) = shift;
my $globalQ = shift;
my $tid = threads->self->tid;
while( my $workItem = $Q->dequeue )
{
for( my $i = 0; $i < @clientList; $i++)
{
#lock $mtxStdOut;
print " workitem from thread $tid -->$workItem\n"
+;
## Perform query
## worked on one client for query signal compBoss to start
+doing comp
## so enqueue the file location on dum
+p
my $fileLoc = "$workItem"."$clientList[$i]";
$globalQ->enqueue($fileLoc);
}
}
}
|