FWIW, this doesn't crash.
#!/usr/bin/perl use 5.10.1; use strict; use warnings; use IO::Socket::INET; use Time::Piece; use Time::HiRes ('sleep'); use DBI; use AutoLoader qw(AUTOLOAD); use POSIX qw(:signal_h); use threads ('stack_size' => 64*4096, 'exit' => 'threads_only', 'stringify'); my $shost = '192.168.0.201'; my $sport = 60004; my $mhost = '192.168.0.201'; my $dbname = 'enterprise'; my $dbuser = 'root'; my $dbpasswd = '123456'; sub send_message { my $message = shift @_; die 'Connect failed!' unless my $sock = 'IO::Socket::INET' ->new( 'PeerAddr', $shost, 'PeerPort', $sport, 'Proto', 'tcp +' ); print $sock $message; } sub get_message { my $dbh = 'DBI'->connect( "DBI:mysql:database=$dbname;host=$mhost" +, $dbuser, $dbpasswd, { 'PrintError', 0, 'RaiseError', 1 } ); my $sth = $dbh->prepare('SELECT IMEI FROM SessionIMEI'); $sth->execute; my @elements; while ( my $ref = $sth->fetchrow_hashref ) { push @elements, $$ref{'IMEI'}; } my $buf = '$0'; foreach my $ref (@elements) { $buf .= ",$ref"; } $buf .= "\@\r\n"; $dbh->disconnect; return $buf; } my $sigset = POSIX::SigSet->new(SIGINT); my $signal = undef; $sigset->delset(\&POSIX::SIGUSR1); $sigset->delset(\&POSIX::SIGINT); $sigset->delset(\&POSIX::SIGALRM); my $old_sigset = POSIX::SigSet->new; sub user_handler { print "Get a user defined signal.\n"; $signal = shift @_; } sub int_handler { print "Get a interrupt signal.\n"; $signal = shift @_; print $signal, "\n"; } sub alarm_handler { print "Get a alarm signal.\n"; $signal = shift @_; } $SIG{'USR1'} = \&user_handler; $SIG{'INT'} = \&int_handler; $SIG{'ALRM'} = \&alarm_handler; unless ( defined sigprocmask( \&SIG_BLOCK, $sigset, $old_sigset ) ) { warn "could not block sigint\n" } else { print "blocked sigint\n"; } sub sig_process { sigsuspend($sigset); my $message = undef; if ( $signal eq 'INT' ) { $message = get_message(); send_message $message; } } sub create_alarm { sub start_thread { my @args = @_; say "Thread started: ", join(' ', @args); } my $thr = 'threads'->create('start_thread', \&alarm_thread); $thr->detach(); if($thr->is_detached) { print "Thread is detached\n"; } else { print "Thread is not detached\n"; } } sub alarm_thread { eval { local $SIG{'ALRM'} = sub { die "alarm\n"; }; alarm 10; my $buffer; my $nread = sysread SOCKET, $buffer, 1; close SOCKET; alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; } else { return; } } create_alarm; sig_process;

In reply to Re: perl threads crashed by Khen1950fx
in thread perl threads crashed by liunx

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.