in reply to Re^8: Problem in Inter Process Communication
in thread Problem in Inter Process Communication

Hi browserUK,

is there some problem in the below code :-

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); } } }

Replies are listed 'Best First'.
Re^10: Problem in Inter Process Communication
by BrowserUk (Patriarch) on Aug 22, 2008 at 08:49 UTC
    is there some problem in the below code

    Yes. You cannot have two different types of worker feeding off the same queue. How will each know whether what it pulled off the queue is for it or for the other type of worker?

    You would at least need to use two queues, which isn't a problem and can be an effective way of decoupling two or more types of processing. But you still need to explain why you think this is a good idea? What are you hoping to gain from doing so?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.