Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Rather than starting/stopping threads to feed input, it would be preferable to feed them work to do. Here is a snipped of the code I use (In production on Windows/perl 58/ Activestate):
use threads; use Thread::Queue; our $KIDS = $count > 20? 10 : int ($count / 4) || 1; # Some way to c +ontrol max # of threads my $work_Q = new Thread::Queue; ## Start the kids my @kids = map{ threads->create( \&kid, $_) } 1 .. $KIDS; $work_Q->enqueue( keys %ServerInfo ); # Feed the QUEUE with work to do + .... ## Tell them to stop $work_Q->enqueue( (undef) x $KIDS ); # THis tells each thread to QUIT ## And wait for Kids to finish.. my %results = map {$_->join} @kids; #---------------------------------------------------- sub kid { my $kidnumber = shift; my @results=(); my $tid = threads->tid; my $count=0; my $pinger = Net::Ping->new("icmp",$TimeOut); #printf "Kid: %02d started<br>\n", $tid; while( my $work = $work_Q->dequeue ) { $count ++; push @results, $work, Ping_it($pinger, $work) ; } push @results,"KID$kidnumber",$count; #print "kid: $tid ending after processing $count items.<br>\n"; return @results; }

     "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom


In reply to Re: Controlling Thread Numbers by NetWallah
in thread Controlling Thread Numbers by BBQ

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2023-03-24 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (61 votes). Check out past polls.

    Notices?