Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi,

Is each thread actually created? What do you get with this wordy program

#!/usr/bin/perl -- use warnings; use strict; use threads; use threads stack_size => 4096, 'exit' => 'threads_only';; Main( @ARGV ); exit( 0 ); sub Main { open my( $data ), '<', \'not,match server1.net,value server2.net,value server3.net,value server4.net,value '; while( my $Serv = <$data> ) { chomp $Serv; my $thread = threads->new( \&runMoo, $Serv ); print tidt( $thread ), "Created thread for $Serv \n"; } while( threads->list ) { for my $thread ( threads->list( threads::joinable ) ) { print tidt( $thread ), "Joining ", $thread->join, "\n"; } Win32::Sleep( 33 ); } print tidt(), "Work complete\n"; } sub runMoo { my( $server ) = @_; Win32::Sleep( rand 4000 ); print tidt(), "Starting runMoo('$server')\n"; if( $server =~ /(\w.+\w\d+.+net),(\w+)/ ) { my $Server = $1; my $Type = $2; print tidt(), "Connecting to $Server\n"; Win32::Sleep( rand 2000 ); } else { print tidt(), "not match server ($server)\n"; } print tidt(), "Done for $server\n"; } sub tidt { my( $thread ) = ( @_, threads->self ); my $tid = $thread->tid; return join '', $tid, " " x $tid, $tid, " "; } __END__ 1 1 Created thread for not,match 2 2 Created thread for server1.net,value 3 3 Created thread for server2.net,value 4 4 Created thread for server3.net,value 5 5 Created thread for server4.net,value 5 5 Starting runMoo('server4.net,value') 5 5 Connecting to server4.net 3 3 Starting runMoo('server2.net,value') 3 3 Connecting to server2.net 1 1 Starting runMoo('not,match') 1 1 not match server (not,match) 1 1 Done for not,match 1 1 Joining 1 5 5 Done for server4.net,value 5 5 Joining 1 3 3 Done for server2.net,value 3 3 Joining 1 4 4 Starting runMoo('server3.net,value') 4 4 Connecting to server3.net 2 2 Starting runMoo('server1.net,value') 2 2 Connecting to server1.net 4 4 Done for server3.net,value 4 4 Joining 1 2 2 Done for server1.net,value 2 2 Joining 1 00 Work complete

In reply to Re: script hanging at thread start by Anonymous Monk
in thread script hanging at thread start by armcinto

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (1)
    As of 2021-02-25 02:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?