threads;
threads::shared;
####
our $D = threads->new(\&Darling::run, ID => 'Darling' );
$D->detach();
...
while (my $client = $server->accept()) { #foreach $client
my $pAddr = $client->peerhost();
...
}
####
$SIG{KILL} = 'mumsDeath';
$SIG{TERM} = 'mumsDeath';
sub mumsDeath {$D->kill('KILL'); print "killing my darling\n";}
####
package Darling;
use threads;
use threads::shared;
our $minID;
sub new { #: create Darling
my $pkg = shift;
my $self = { @_ };
return bless($self, $pkg); ##: arr of blessed (self, pkg)
}
sub catchBullet {
print "\n\n$0 :: $minID SIGNAL caught !!\n";
}
sub run {
my $self = MinBar->new(@_); #: Me
$minID = $self->{ID}; #:
$|++;
$SIG{TSTP} = 'catchBullet';
$SIG{INT} = 'catchBullet';
$SIG{TERM} = 'catchBullet';
$SIG{KILL} = 'catchBullet';
$SIG{QUIT} = 'catchBullet';
$SIG{STOP} = 'catchBullet';
$SIG{USR2} = 'catchBullet';
$SIG{USR1} = 'catchBullet';
print "$0 :: $minID starting: ";
while ( 1 ) {
sleep 30;
print "."
}
}