pg has asked for the wisdom of the Perl Monks concerning the following question:

I did some testing, and came to the conclusion that, Perl only supports signals in a per process semantic, but not a per thread semantic.

The testing I did is simple: I start a process with two threads, then set up $SIG{ALRM} handler, and call alarm. It doesn't matter whether you call alarm from the main thread or the created thread, the SIGALRM is always delivered to the main thread, i.e. the process. You can imagine that, if I only set up $SIG{ALRM} for the created thread, but not the main thread, then the process will go down, which is the default handling for SIGALRM. ( I tried the same thing for SIGINT with CTRL-C)

Did I lie when I say, Perl only supports per process signal? If yes, I lied, then how to do it in a per thread semantic? I only tested Win, is it different on UNIX? especially Solaris, which I know supports per thread semantic.

Replies are listed 'Best First'.
Re: per thread signal?
by Elian (Parson) on Nov 22, 2002 at 21:12 UTC
    Signals are process-level constructs. This doesn't have anything to do with perl as such--it's the way POSIX threads are defined. Asynchronous signals act on the entire process, rather than on any individual thread. (Or should, for a POSIX conformant thread implementation)

    Quite a few people would have preferred signals act on individual threads, but this has its own set of problems. Neither way is particularly great, and each sucks in its own unique fashion. The POSIX folks chose the whole process route. Just one of those things.

Re: per thread signal?
by rob_au (Abbot) on Nov 22, 2002 at 23:00 UTC
    You may want to have a look at the Thread::Signal package on CPAN - This module is described as allowing signals to be delivered to specific "threads" on systems that employ separate (pseudo-)processes for each "thread". At this stage, this module only works under Linux on Perl 5.8.0 with thread support.

    Not a true solution, but something interesting to consider ... :-)

     

    perl -e 'print+unpack("N",pack("B32","00000000000000000000000111101011")),"\n"'