home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D2.iso / workshop / apache / files / ActivePerl-5.6.1.638-MSWin32-x86.msi / _564058b024ccea9f0004c52bc3aaff9c < prev    next >
Encoding:
Text File  |  2004-04-13  |  1.3 KB  |  55 lines

  1. package Thread::Signal;
  2. use Thread qw(async);
  3.  
  4. =head1 NAME
  5.  
  6. Thread::Signal - Start a thread which runs signal handlers reliably
  7.  
  8. =head1 SUPPORTED PLATFORMS
  9.  
  10. none
  11.  
  12. =head1 SYNOPSIS
  13.  
  14.     use Thread::Signal;
  15.  
  16.     $SIG{HUP} = \&some_handler;
  17.  
  18. =head1 DESCRIPTION
  19.  
  20. The C<Thread::Signal> module starts up a special signal handler thread.
  21. All signals to the process are delivered to it and it runs the
  22. associated C<$SIG{FOO}> handlers for them. Without this module,
  23. signals arriving at inopportune moments (such as when perl's internals
  24. are in the middle of updating critical structures) cause the perl
  25. code of the handler to be run unsafely which can cause memory corruption
  26. or worse.
  27.  
  28. =head1 BUGS
  29.  
  30. This module changes the semantics of signal handling slightly in that
  31. the signal handler is run separately from the main thread (and in
  32. parallel with it). This means that tricks such as calling C<die> from
  33. a signal handler behave differently (and, in particular, can't be
  34. used to exit directly from a system call).
  35.  
  36. =cut
  37.  
  38. if (!init_thread_signals()) {
  39.     require Carp;
  40.     Carp::croak("init_thread_signals failed: $!");
  41. }
  42.  
  43. async {
  44.     my $sig;
  45.     while ($sig = await_signal()) {
  46.     &$sig();
  47.     }
  48. };
  49.  
  50. END {
  51.     kill_sighandler_thread();
  52. }
  53.  
  54. 1;
  55.