Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

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