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

RE: threads and alarm

Thread Previous | Thread Next
From:
dannwong
Date:
September 1, 2011 23:05
Subject:
RE: threads and alarm
Message ID:
D59C59453D0EDC43832490B6DADFAECF046185EA@XMB-RCD-214.cisco.com
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