develooper Front page | perl.ithreads | Postings from September 2011

Re: threads and alarm

Thread Previous | Thread Next
From:
Jerry D. Hedden
Date:
September 1, 2011 10:54
Subject:
Re: threads and alarm
Message ID:
CABcAEYx2ooDKZ3ZnEBe47vM0XrWpLjc9n+c1K57Nc8pjBSysyQ@mail.gmail.com
The ->kill() method for threads was added in threads v1.27 (back in
May 2006).  If you update the threads module, you'll have this
capability.  The 'best' way to do this is to install Bundle::Thread
from CPAN.

On Thu, Sep 1, 2011 at 13:27, Danny Wong (dannwong) <dannwong@cisco.com> wrote:
> How can you do this using perl 5.8.8?
>
> -----Original Message-----
> From: jdhedden@gmail.com [mailto:jdhedden@gmail.com] On Behalf Of Jerry D. Hedden
> Sent: Thursday, September 01, 2011 5:48 AM
> To: alfonso caponi
> Cc: perl-ithreads@perl.org
> Subject: Re: threads and alarm
>
> 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.caponi@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
>>
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About