L
LovingFox
I've got some kind of problem using threads module with Sys::SigAction
module. Look to this too examples:
1. The first (function 't' w/o threads) works good as I need:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use Sys::SigAction qw( set_sig_handler );
t();
sub t {
eval {
set_sig_handler( 'ALRM', sub { die 'alarm!' } );
alarm(1);
sleep(2); # here is some usefull code instead 'sleep'
alarm(0);
};
print "end '$@'\n";
}
-------------------------------------------------------------------------
2. The second (function 't' through threads) prints error I cannot
understand:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use threads;
use Sys::SigAction qw( set_sig_handler timeout_call );
threads->new( \&t )->join();
sub t {
eval {
set_sig_handler( 'ALRM', sub { die 'alarm!' } );
alarm(1);
sleep(2);
alarm(0);
};
print "end '$@'\n";
}
module. Look to this too examples:
1. The first (function 't' w/o threads) works good as I need:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use Sys::SigAction qw( set_sig_handler );
t();
sub t {
eval {
set_sig_handler( 'ALRM', sub { die 'alarm!' } );
alarm(1);
sleep(2); # here is some usefull code instead 'sleep'
alarm(0);
};
print "end '$@'\n";
}
-------------------------------------------------------------------------
2. The second (function 't' through threads) prints error I cannot
understand:
-------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use threads;
use Sys::SigAction qw( set_sig_handler timeout_call );
threads->new( \&t )->join();
sub t {
eval {
set_sig_handler( 'ALRM', sub { die 'alarm!' } );
alarm(1);
sleep(2);
alarm(0);
};
print "end '$@'\n";
}