use strict; use threads; use threads::shared; use Thread::Semaphore; use POSIX; my @clientList = qw(client1 client2 client3 client4 client5 client6 cl +ient7 client8 client9 client10 client11 client12); my @dmServers = qw +(A B C); my @queryPath = qw(AA BB CC DD EE FF); my @shared; my $query +Index = 0; my $maxnoofThreads = 2; my %sharedHash : shared; for (my $i = 0;$i < @dmServers;$i++) { my $cpid = fork(); die unless defined $cpid; if (! $cpid) { # This is the child # my $wait = int rand 10; # sleep $wait; callChild($queryPath[$queryIndex++],$dmServers[$i +],$i); #print "Child $$ exiting after seconds\n"; exit; } } # Just parent code, after this while ((my $cpid = wait()) != -1) { #print "Waited for child $cpid\n"; #print " length of array shared",length(@shared); } #print "Parent Exiting\n"; sub callChild { my $query = shift; my $dmserver = shift; my $i = shift; #print " query fired $query on dmserver $dmserver index $i\n"; my @clientList_temp = @clientList; for(my $index = $i; $index < @queryPath;$index = $index + @dmS +ervers) { print "process $$ query at $index is ",$queryPath[$i +ndex],"\n"; # $shared[$i] = $i; # sleep rand(10); for(my $a;$a <= $maxnoofThreads;$a++) { my $sema = Thread::Semaphore->new(); my @temp = splice(@clientList_temp,0,ceil(@clientL +ist/$maxnoofThreads)); my $thr = thread->new(\&worker,$sema,\@temp,$query +Path[$index]); #if( defined %sharedHash) # { # my $thrnew = thread->new(\&compare); # $sema->up; # } } foreach my $thr (threads->list) { # Don't join the main thread or ourselves if ($thr->tid && !threads::equal($thr, th +reads->self)) { ##########Not Sure ####### foreach my $client ( +keys %sharedHash) { print " client $client\n"; my $thrnew = thread->new(\&compar +e,$client); $sema->up; } $thr->join; } } } #$shared[$i] = undef; } sub worker { my $sema = shift; my $myClientArrayRef = shift; my $query = shift; for(my $i;$i < @$myClientArrayRef;$i++) { print " $$myClientArrayRef[$i] client \n"; sleep 5; my $thrid = threads->tid; $sharedHash{$$myClientArrayRef[$i]} = $thrid; shift @$myClientArrayRef; $sema->down; } } sub compare { my $client = shift; print " hash value ",$sharedHash{$client},"\n"; }

In reply to Re^2: Problem in Inter Process Communication by libvenus
in thread Problem in Inter Process Communication by libvenus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.