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

Hi wise monks, I seek knowledge about using signals and threads together:

1. When a signal occurs, which thread gets the signal, will it always be the original parent?

2. Is trying to lock a shared variable in a signal alarm dangerous (in that the lock may never succeed if the main thread which has been interrupted by the alarm already has the lock)?

3. What is an easy and tidy way for the original parent thread to check if a child thread is no longer running (because it has crashed for example).

Replies are listed 'Best First'.
Re: Signals to threads
by Corion (Patriarch) on May 08, 2016 at 07:11 UTC

    Don't mix threads and signals. The interactions are not well-defined.

    Using threads, you can look at $thread->error to find if $thread has crashed.

Re: Signals to threads
by Preceptor (Deacon) on May 10, 2016 at 11:14 UTC

    Seconding what Corion said - mixing signals and threads is messy, and often unnecessary.

    As for checking whether it's still running though - you can check thread state by testing "running":

    my @running = threads->list(threads::running); my @joinable = threads->list(threads::joinable);

    Or per thread:

    foreach my $thr ( threads -> list ) { print $thr. " is running\n" if $thr -> is_running(); print $thr. " is joinable\n" if $thr -> is_joinable(); }