Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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]
[stevieb]: Hey ww. Just laying down watching a hockey game, running my auto build distribution that automates Strawberry installs to figure out which ones had csum changes so berrybrew doesn't barf on those ones
[stevieb]: ...and closing some issues on some of my other dists

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-03-30 02:58 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (353 votes). Check out past polls.