Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: script hanging at thread start

by GrandFather (Saint)
on Nov 24, 2020 at 20:39 UTC ( #11124162=note: print w/replies, xml ) Need Help??


in reply to script hanging at thread start

When I run:

use warnings; use strict; use threads; my @Threads; for my $Serv (<DATA>) { chomp $Serv; print "Created thread for $Serv\n"; push @Threads, threads->new(sub {runMain($Serv)}); } $_->join() for @Threads; print "Work complete\n"; sub runMain { my ($server) = @_; print "Starting runMain('$server')\n"; if ($server =~ /(\w.+\w\d+.+net),(\w+)/) { my $Server = $1; my $Type = $2; print "Connecting to $Server\n"; } print "Done for $server\n"; } __DATA__ server1.net,value server2.net,value server3.net,value server4.net,value

it prints:

Created thread for server1.net,value Created thread for server2.net,value Starting runMain('server1.net,value') Connecting to server1.net Done for server1.net,value Created thread for server3.net,value Starting runMain('server2.net,value') Connecting to server2.net Done for server2.net,value Created thread for server4.net,value Starting runMain('server3.net,value') Connecting to server3.net Done for server3.net,value Starting runMain('server4.net,value') Connecting to server4.net Done for server4.net,value Work complete

How is your code different?

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: script hanging at thread start
by armcinto (Initiate) on Nov 24, 2020 at 21:12 UTC
    In your example I get Created thread for server1 - 4, but only 3 will get the other output. For example I would not see Starting runMain('server3.net,value'), Connecting to server3.net, Done for server3.net.

      A bug in threads maybe? I'm running "This is perl 5, version 32, subversion 0 (v5.32.0) built for MSWin32-x64-multi-thread".

      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2021-02-25 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?