use strict; use threads; use threads::shared; use Thread::Queue; my @queryList = qw(/dev/files_xls_tmpl_cfg_nonscripts/sql1.clmod.NEW.txt /dev/files_xls_tmpl_cfg_nonscripts/sql1.clmod.NEW14-78B6R.txt /dev/files_xls_tmpl_cfg_nonscripts/sql1.clmod.NEW14-78B7N.txt /dev/files_xls_tmpl_cfg_nonscripts/Interest_on_Cash_PATS_cmt_dt.clmod.txt /dev/files_xls_tmpl_cfg_nonscripts/Interest_on_Cash_PATS_cmt_dt.clmod14-78B6R.txt /dev/files_xls_tmpl_cfg_nonscripts/Interest_on_Cash_PATS_cmt_dt.clmod14-78B7N.txt ); print $ARGV[0],"\n"; my $maxnoofQueryThreads = $ARGV[0]; my $maxnoofCompThreads = 2*$ARGV[0]; my $globalQ : shared = new Thread::Queue; my $q = new Thread::Queue; my $defSig = undef; my $queryBossID = threads->new(\&queryBoss,$globalQ,$q); my $compBossID = threads->new(\&compBoss,$globalQ,); $queryBossID->join; $compBossID->join; sub queryBoss { print " query boss triggered\n"; my $globalQ = shift; my $q = shift; my @queryworkers = map {threads->new( \&queryworker, $q,$globalQ,$_);} 1 .. $maxnoofQueryThreads; $q->enqueue(@queryList); $q->enqueue( ( undef ) x $maxnoofQueryThreads ); $_->join for @queryworkers; } sub compBoss { print " comp boss triggered\n"; my $globalQ = shift; print " i am comp boss and i can see the following items\n",$globalQ->pending; #while(my $workItem = $globalQ->dequeue) { my @compworkers = map {threads->new( \&compworker, $globalQ,$_);} 1 .. $maxnoofCompThreads; #$q->enqueue(@queryList); $globalQ->enqueue( ( undef ) x $maxnoofCompThreads ); $_->join for @compworkers; } sub compworker { print " comp worker triggered\n"; my $globalQ = shift; my $id = shift; my $tid = threads->self->tid; print " i am comp worker and i can see the following items\n",$globalQ->pending; while(my $workItem = $globalQ->dequeue){ print " id $id the file is $workItem \n"; print " i must compare the following file $workItem \n"; #start comparison on the file and dump result in a new file and del the file } } sub queryworker { print " query worker triggered\n"; my( $Q ) = shift; my $globalQ = shift; my $id = shift; my $tid = threads->self->tid; while( my $workItem = $Q->dequeue ){ local $/ = undef; #system("client hqsas501 22415 200 \-f $workItem > $workItem\.prod"); open(HAN,"client hqsas501 22415 200 \-f $workItem |") || die "$!"; my $prod = ; #print "prod file slurped $prod\n"; close HAN; #system("client hqsas501 22710 200 \-f $workItem > $workItem\.test"); open(HAN,"client hqsas501 22710 200 \-f $workItem |") || die "$!"; my $test = ; #print "test file slurped $test\n"; close HAN; my $handleProd = $workItem.'prod'; my $handleTest = $workItem.'test'; unless($prod eq $test){ open(HANPRD,">$handleProd") || die "$!"; open(HANTST,">$handleTest") || die "$!"; print " thread it $tid working on $workItem prod and test file differ \n"; print HANPRD $prod; print HANTST $test; print " enqueing workitem $workItem\n"; $globalQ->enqueue($workItem); print "$compBossID compbossid\n"; #$compBossID->kill(ALRM); close HANPRD; close HANTST; } print " i am query worker and i can see the following items\n",$globalQ->pending; } }