Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Alarm In Perl

by meena (Novice)
on Jul 25, 2013 at 10:49 UTC ( #1046316=perlquestion: print w/replies, xml ) Need Help??
meena has asked for the wisdom of the Perl Monks concerning the following question:

Alarm::Queued methods like setalarm,clearalarm not working when I use them in Perl threads;When I create a thread and want to setalarm it doesnt work
use threads; my $call = threads->create(\&methodinvoke); my @ReturnData = $call->join(); print('Thread returned ', join(', ', @ReturnData), "\n"); sub methodinvoke { use Alarm::Queued qw( :OVERLOAD :ALL ); setalarm(2, sub { print "bing" }); }

Replies are listed 'Best First'.
Re: Alarm In Perl
by hippo (Canon) on Jul 25, 2013 at 11:28 UTC

    Your alarm is set in the thread. The thread finishes before the alarm is triggered, therefore the alarm is not triggered. Where's the problem?

Re: Alarm In Perl
by meena (Novice) on Jul 25, 2013 at 11:44 UTC
    If I want to invoke from a thread an alarm in main ,How will I achieve that, Sorry I forgot to add a sleep(3); in the thread Still it doesnot work

      I. Reading perldoc -f alarm on your console might be helpful.

      II. "not working" and "doesn't work" are NOT usually useful descriptions -- are you seeing any messages about your initial error? If so, quote it. If not, at least be specific about "how" it's "not working."

      III. Did you note that your OP has been considered for code tags? If not, please do note, and return to your top post to insert the tags described at the text entry box.

      If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.
      I want to invoke from a thread an alarm in main ,How will I achieve that,

      You cannot. Any signal raised within your thread will only be seen by that thread; not main.

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I want to send a message from thread to main so that some operation can be performed in the main Eg: alarm can be set in main

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1046316]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2018-06-20 20:07 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.