Here is the parred down code and where the error occurs:
use strict; use IO::Socket; use threads; use threads::shared; my $numClients = shift; my %thread_status : shared; my $server_status : shared = 'threading'; $| = 1; my $screen_output : shared = 1; my $HOST = 'cdt-2x4w227x'; my $PORT = 7001; # Launch clients in their own thread print "Creating $numClients clients\n"; for (my $i=0; $i<$numClients; $i++) { my ($retries,$socket); $socket = IO::Socket::INET->new("$HOST:$PORT") || print "Socket cr +eation error: $!\n"; while (!$socket) { print "Retrying socket connection for client $i\n"; $retries++; if ($retries > 5) { print "Exceeded retries while launching client $i\n"; last; } sleep 1; $socket = IO::Socket::INET->new("$HOST:$PORT") || print "Socke +t creation error on retry $retries: $!\n"; } if ($socket) { my $t = threads->new(\&handle_client,$socket,$i)->d +etach } else { print " Error creating socket: $i\n" } print "."; } print "Done creating clients\n"; sleep 1; $server_status = 'ready'; print "Waiting for client threads to finish\n"; while (my @keys = keys %thread_status) { my $count = @keys; print &time_stamp," Waiting for [$count] threads from [@keys]\n"; sleep 1; } sleep 1; #<------------------------------------------------------------ handle_ +client --> sub handle_client { my ($socket,$clientNum) = @_; my $line; my $tid = threads->self->tid; my $timeout = 2; $thread_status{$clientNum} = $clientNum; while ($server_status eq 'threading') { sleep 1 } #VINI print " $clientNum -> VINI\n" unless (!$screen_output); if ($socket) { $socket->send("VINI\n") || $socket->close && undef +$socket && return } ^^^^^^ FAILS ON SEND ^^^^^^^ $line = <$socket> if ($socket); print " $clientNum <- $line" unless (!$screen_output); sleep rand($timeout); lock %thread_status; delete $thread_status{$clientNum}; $socket->close; threads->self->yield; return; }
Error is: thread failed to start: Can't call method "send" without a package or object reference at thread_test.pl line 60

So it looks like you're right about the timeout. So how would one handle and recover from such a time out? Thanks!


In reply to Re: Re: thread failed to start? by noslenj123
in thread thread failed to start? by noslenj123

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, details, 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, summary, 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.