source: for-distributions/trunk/bin/windows/perl/lib/Thread/Signal.pm@ 14489

Last change on this file since 14489 was 14489, checked in by oranfry, 17 years ago

upgrading to perl 5.8

File size: 2.2 KB
Line 
1package Thread::Signal;
2use Thread qw(async);
3
4our $VERSION = '1.00';
5
6=head1 NAME
7
8Thread::Signal - Start a thread which runs signal handlers reliably (for old code)
9
10=head1 CAVEAT
11
12For new code the use of the C<Thread::Signal> module is discouraged and
13the direct use of the C<threads> and associated modules is encouraged instead.
14
15However, there is no direct equivalent of the Thread::Signal module in the
16new implementation of threads. On the bright side: signals are now delivered
17reliably to Perl programs that do not use threads. The handling of signals
18with the new threading features is up to the underlying thread implementation
19that is being used and may therefor be less reliable.
20
21If you want to specify a thread-specific signal, you can alter the %SIG hash
22in the thread where you want to handle a signal differently from other threads.
23This at least seems to work under Linux. But there are no guarantees and your
24mileage may vary.
25
26For the whole story about the development of threads in Perl, and why you
27should B<not> be using this module unless you know what you're doing, see the
28CAVEAT of the C<Thread> module.
29
30=head1 SYNOPSIS
31
32 use Thread::Signal;
33
34 $SIG{HUP} = \&some_handler;
35
36=head1 DESCRIPTION
37
38The C<Thread::Signal> module starts up a special signal handler thread.
39All signals to the process are delivered to it and it runs the
40associated C<$SIG{FOO}> handlers for them. Without this module,
41signals arriving at inopportune moments (such as when perl's internals
42are in the middle of updating critical structures) cause the perl
43code of the handler to be run unsafely which can cause memory corruption
44or worse.
45
46=head1 BUGS
47
48This module changes the semantics of signal handling slightly in that
49the signal handler is run separately from the main thread (and in
50parallel with it). This means that tricks such as calling C<die> from
51a signal handler behave differently (and, in particular, can't be
52used to exit directly from a system call).
53
54=cut
55
56if (!init_thread_signals()) {
57 require Carp;
58 Carp::croak("init_thread_signals failed: $!");
59}
60
61async {
62 my $sig;
63 while ($sig = await_signal()) {
64 &$sig();
65 }
66};
67
68END {
69 kill_sighandler_thread();
70}
71
721;
Note: See TracBrowser for help on using the repository browser.