use base 'Exporter'; use strict; use vars qw($VERSION @ISA @EXPORT); use threads; use threads::shared; use mUtils qw/callerDepth -1/; use communicate; #my @arr; #my @arr3; #share(@arr3); #share(@arr); my $pipe1 = communicate->new(pipeDepth => -1, callerDepth => 1, pid => 'clientQueue'); my $key = $pipe1->getCid(); printMsg "Got key: $key","Info"; my $tPut1 = threads->create(\&keepPut1); my $tPut2 = threads->create(\&keepPut2); sleep 60; my $tGet1 = threads->create(\&keepGet1); my $tGet2 = threads->create(\&keepGet2); $tPut1->join(); $tPut2->join(); sleep 2; print "\n======================\n"; #print "Array size : $#arr3\n"; #print "Array size : $#arr\n"; print "\n======================\n"; $tGet2->join(); $tGet1->join(); sub keepPut1 { printMsg "In Put1"; my $count = 0; while($count<500) { printMsg "1. Putting Count => $count"; $pipe1->put($count); #lock(@arr3); #push(@arr3,$count); if($count%10==0) { sleep .1;} $count++; #sleep 0.1; } return 0; } sub keepPut2 { printMsg "In Put2"; my $count = 500; while($count<500) { printMsg "2. Putting Count => $count"; $pipe1->put($count); #lock(@arr3); #push(@arr3,$count); $count++; #sleep 0.1; } return 0; } sub keepGet1 { printMsg "In Get 1"; my $pipe = communicate::getObject($key); while(1) { my $countGet = $pipe1->get(); #printMsg "Got count: $countGet"; if(!defined($countGet)) { print "Vola\n"; sleep 10; } else { printMsg "1. Got from pipe => $countGet"; #lock(@arr); #push(@arr,$countGet); } #sleep 0.1; } print "Get1 ends.. "; } sub keepGet2 { printMsg "In Get 2"; my $pipe = communicate::getObject($key); while(1) { my $countGet = $pipe1->get(); #printMsg "Got count: $countGet"; if(!defined($countGet)) { print "Vola\n"; sleep 10; } else { printMsg "2. Got from pipe => $countGet"; #lock(@arr); #push(@arr,$countGet); } #sleep 0.1; } print "Get2 ends.. "; } printErr "---------------------------------";