http://www.perlmonks.org?node_id=923590

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

How can i send signal from child thread to main thread? I need to send signal to all threads including main. This doesn't work:
$_->kill('HUP') foreach threads->list;

I'm using ActiveState perl on Windows platform.

Replies are listed 'Best First'.
Re: Send signal to main thread
by Corion (Patriarch) on Sep 01, 2011 at 09:21 UTC

    Signals and threads don't mix well. Neither on Windows nor on Unix / POSIX threads. Don't do it.

    Update: cdarke points out that I'm mistaking the signals that threads implements for inter-thread signaling with the OS signals. As you are using the threads signals, ignore my comment.

      When using threads, catching a Ctrl-C to close up your program gracefully is a nightmare.

      While threads signals may work fine, catching signals from the terminal, such as Ctrl-C, still poses a difficult problem with no good solution (that I've encountered). There is no way to know which thread is going to receive the signal because the terminal sends the signal to the process group, not to a thread.