S
Samuel
The following code:
--------------
#!/usr/bin/perl
use threads;
sub run {
my $result = eval q{
local $SIG{ALRM} = sub { die "timed-out\n" };
alarm 2;
sleep 10;
alarm 0;
};
if ($@) {
print "Error: $@\n";
}
}
print "Running in main thread...\n";
run2();
print "Returned. Running in new thread...\n";
my $thread = threads->new(\&run2);
print "Joining...\n";
$thread->join();
print "Done.\n";
--------------
Produces the following output:
--------------
$ perl alrmtst.pl
Running in main thread...
Error: timed-out
Returned. Running in new thread...
Joining...
Alarm clock
$
--------------
Can anyone explain why the SIGALRM is caught in the main thread but
not in the new thread? How do you catch SIGALRM in the second case?
-Samuel
--------------
#!/usr/bin/perl
use threads;
sub run {
my $result = eval q{
local $SIG{ALRM} = sub { die "timed-out\n" };
alarm 2;
sleep 10;
alarm 0;
};
if ($@) {
print "Error: $@\n";
}
}
print "Running in main thread...\n";
run2();
print "Returned. Running in new thread...\n";
my $thread = threads->new(\&run2);
print "Joining...\n";
$thread->join();
print "Done.\n";
--------------
Produces the following output:
--------------
$ perl alrmtst.pl
Running in main thread...
Error: timed-out
Returned. Running in new thread...
Joining...
Alarm clock
$
--------------
Can anyone explain why the SIGALRM is caught in the main thread but
not in the new thread? How do you catch SIGALRM in the second case?
-Samuel