Signals are received by thread 0 - the main thread. Therefore, when a thread sets an alarm, the ALRM signal hits the main thread not the thread that set the alarm. I don't know your particular needs, but if you want the thread to get the alarm, then you need to set the alarm handler in the main thread, and then send the ALRM signal to the thread using $thr->kill('ALRM'). Thus, in your example, if you add the following:
$thr->detach(); $SIG{ALRM} = sub { $thr->kill('ALRM') }; It'll work. On Thu, Sep 1, 2011 at 06:08, alfonso caponi <alfonso.cap...@gmail.com> wrote: > 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 >