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


in reply to The implementation of SIGHUP in Win32 Perl

What happens if the main thread terminates while the signal handler thread is still sleeping? And what happens if there's another SIGHUP while the signal handler thread is still sleeping?

  • Comment on Re: The implementation of SIGHUP in Win32 Perl

Replies are listed 'Best First'.
Re^2: The implementation of SIGHUP in Win32 Perl
by klaten (Novice) on Aug 31, 2013 at 19:34 UTC

    Regarding what happens if the main thread terminated, I assume that the termination is due to the Perl program stopping. Then, the C function, exit(), in the runtime library (called by Perl when stopping) would use the Win32 ExitProcess() system call and would take down all the process threads including the signal handler thread.

    Regarding what happens if there's another SIGHUP, the SIGHUP is actually coming from the control handler code which is triggered by a Win32 CTRL_CLOSE_EVENT. Keep in mind that under later versions of Windows, a single CTRL_CLOSE_EVENT means a process is doomed! Soon, or very soon, it's going down! So even if a second SIGHUP came in and caused a segfault in Perl the only thing that would be lost is a cleanup opportunity that we aren't even taking advantage of right now.

    Now, about that second or subsequent SIGHUP. Let's say it does get triggered and the sig_terminate(aTHX_ 1); from win32.c activates the $SIG{ 'HUP' } in the Perl program. I imagine it would have the same effect as any other repeated signal in Perl, that is the effect would depend on the $SIG handler, maybe it segfaults, maybe its ignored, maybe . . ., but it would be the same as in Linux or elsewhere.