Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: Thread Design help

by perlCrazy (Monk)
on Sep 11, 2010 at 06:46 UTC ( #859723=note: print w/replies, xml ) Need Help??

in reply to Re^2: Thread Design help
in thread Thread Design help

How the below blocks will get executed ? This is my my first thread program, want to understand in details.
My requirement : i will have 1000's of data server which will be diveided in different groups. Now if I start this program, will all 1000's of dataserver be processed by 10 or 20 threads.
Also this has to be keep running based on some interval time. Once we put all serverrs in enqueue, how each thread will pick up the data.
note: each dataserver will be on different host and port so connection will be independent. Thanks for help.
# Tell each thread that we're done for (1..$THREADS) { #####what is this block doing $request->enqueue(undef); }; # Launch our threads for (1..$THREADS) { async(\&getData); };

Replies are listed 'Best First'.
Re^4: Thread Design help
by Corion (Pope) on Sep 11, 2010 at 08:26 UTC

    As an aside, you should maybe consider actually replying to the person posting code instead of replying to yourself. If you reply to another person, that person will get notified of your post.

    The first part of the code is simply a loop that puts one undef for each thread into the queue. As all the thread code is written to stop when it encounters an undef, this serves to tell the threads that they are done. See See Thread::Queue for the ->enqueue command.

    The second part simply launches the subroutine getData in a separate thread. See threads.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://859723]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2018-06-24 11:18 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.