Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Thread Design help

by perlCrazy (Monk)
on Sep 11, 2010 at 06:46 UTC ( [id://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 (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://859723]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-24 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found