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

Re: script hanging at thread start

by Anonymous Monk
on Dec 03, 2020 at 00:41 UTC ( #11124556=note: print w/replies, xml ) Need Help??


in reply to script hanging at thread start

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11124556]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found

    Notices?