Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://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":



  • 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?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found