Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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


Comment on Re^3: Thread Design help
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://859723]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-12-21 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (107 votes), past polls