Hi list,

I need help! :) How can I use "alarm" without exit from a thread only
(without making the script end!).

For example this works (without threads):

while(1){
        eval {
                local $SIG{ALRM} = sub { print "alarm!\n"; };
                alarm(2);
                print "hi\n";
                sleep 5;
                alarm(0);
        };
}

but the script in attachment doesn't works :(

Thank you very much,
Al
#!/usr/bin/perl

use strict;
use warnings;

use threads;

$|=1;

$SIG{INT} = sub {
        threads->exit();
        exit(1);
};

my $thr = threads->new(\&Testsub);
$thr->detach();

while(1){
}

exit(0);

sub Testsub{

        while(1){
                eval {

                        local $SIG{ALRM} = sub { print "alarm!\n"; };

                        alarm(2);

                        sleep 5;

                        alarm(0);
                };
        }
}

Reply via email to