in reply to Re^4: Perl5.8.4 , threads - Killing the "async" kid
in thread Perl5.8.4 , threads - Killing the "async" kid
From this I assumed that each thread gets its own signal handler.
Each thread may have the signal handler sub somewhere in its memory space, but it will only ever be called on the main thread. I cannot point you to any documentation that states this, but it is easily demonstrated.
This creates 100 threads that wake up every 1/100th of a second. The main thread only wakes up once per second. I put the odds that the main thread (thread 0) will be in control at the given moment when you type ^C as 10,000 to 1 against, and yet no matter how many times you hit ^C, it will always be thread 0 that calls the signal handler:
#! perl -slw use strict; use threads ( stack_size => 4096 ); $SIG{ INT } = sub { warn threads->tid; }; sub thread { 1 while Win32::Sleep 10; } my @threads = map async( \&thread ), 1 .. 100; 1 while sleep 1; __END__ C:\test>junk63 0 at C:\test\junk63.pl line 7. 0 at C:\test\junk63.pl line 7. 0 at C:\test\junk63.pl line 7. 0 at C:\test\junk63.pl line 7. 0 at C:\test\junk63.pl line 7. 0 at C:\test\junk63.pl line 7.
Try it for yourself; modify it to use sigtrap; send signals from other processes. It will always be thread 0 that responds. At least on recent perls, 5.8.9 and later. I'm fairly confident it should also be the case on earlier perls, but I haven't tried it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Perl5.8.4 , threads - Killing the "async" kid
by MonkeyMonk (Sexton) on Oct 14, 2010 at 14:52 UTC | |
by BrowserUk (Patriarch) on Oct 14, 2010 at 15:18 UTC |