in reply to Re^3: Threads, bash, and networking
in thread Threads, bash, and networking

alarms raised in the created thread were indeed caught by the main thread.

Which versions of Perl & threads?

I ask, because that is not what I see:

perl -Mthreads -E" $SIG{ALRM}=sub{die qq[main:Awooga!\n]}; async{ local $SIG{ALRM} = sub{ die qq[thread:Awooga\n] }; alarm 3; sleep 5 }->detach; sleep 7;" Thread 1 terminated abnormally: thread:Awooga

The alarm goes off, the thread-local signal handler catches it and executes and dies, the main thread then completes in the normal way.

Replies are listed 'Best First'.
Re^5: Threads, bash, and networking
by juster (Friar) on Oct 23, 2010 at 07:22 UTC
    When I run your code example, "main:Awooga!" is printed. When I comment out the top $SIG{ALRM} assignment, "Alarm clock" is printed. Here is the perl version for my linode:
    [juster@artemis ~]$ perl -v This is perl 5, version 12, subversion 1 (v5.12.1) built for i686-linu +x-thread-multi Copyright 1987-2010, Larry Wall ...
    Here is the version for my macbook. This perl behaves identically to the above perl in the way I mentioned at the top of this note.
    bash-3.2$ perl -v This is perl, v5.10.0 built for darwin-thread-multi-2level (with 2 registered patches, see perl -V for more detail) Copyright 1987-2007, Larry Wall ...
      When I run your code example, "main:Awooga!" is printed.

      Hm. Looks like another *nix/windows difference in implementation. I agree with you, that renders alarm in threads pretty much useless on *nix.

      Which is a shame because it is (currently) quite useful on windows. Presumably because all signals are just emulations there.

      I also think that in general mixing signals and threads is a bad idea, but I make this one exception for SIGALRM.


      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.