Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: win32, ctrl-c, sleep, and signals

by BrowserUk (Pope)
on May 30, 2006 at 17:11 UTC ( #552555=note: print w/replies, xml ) Need Help??

in reply to Re^2: win32, ctrl-c, sleep, and signals
in thread win32, ctrl-c, sleep, and signals

You have to remember that Win32 does not have signals as a native concept. Perl's support for them is simulated and limited, and is actually implemented via the process message queue. This is the code that implements the signal emulations from win32.c:

void sig_terminate(pTHX_ int sig) { Perl_warn(aTHX_ "Terminating on signal SIG%s(%d)\n",PL_sig_name[si +g], sig); /* exit() seems to be safe, my_exit() or die() is a problem in ^C +thread */ exit(sig); } DllExport int win32_async_check(pTHX) { MSG msg; int ours = 1; /* Passing PeekMessage -1 as HWND (2nd arg) only get PostThreadMes +sage() messages * and ignores window messages - should co-exist better with windo +ws apps e.g. Tk */ while (PeekMessage(&msg, (HWND)-1, 0, 0, PM_REMOVE|PM_NOYIELD)) { int sig; switch(msg.message) { #if 0 /* Perhaps some other messages could map to signals ? ... */ case WM_CLOSE: case WM_QUIT: /* Treat WM_QUIT like SIGHUP? */ sig = SIGHUP; goto Raise; break; #endif /* We use WM_USER to fake kill() with other signals */ case WM_USER: { sig = msg.wParam; Raise: if (do_raise(aTHX_ sig)) { sig_terminate(aTHX_ sig); } break; } case WM_TIMER: { /* alarm() is a one-shot but SetTimer() repeats so kill it + */ if (w32_timerid && w32_timerid==msg.wParam) { KillTimer(NULL,w32_timerid); w32_timerid=0; } else goto FallThrough; /* Now fake a call to signal handler */ if (do_raise(aTHX_ 14)) { sig_terminate(aTHX_ 14); } break; } /* Otherwise do normal Win32 thing - in case it is useful */ default: FallThrough: TranslateMessage(&msg); DispatchMessage(&msg); ours = 0; break; } } w32_poll_count = 0; /* Above or other stuff may have set a signal flag */ if (PL_sig_pending) { despatch_signals(); } return ours; }

Setting the environment variable PERL_SIGNALS=unsafe allows ^C to interupt sleep. Without it, the signal handler doesn't get invoked until the sleep is over.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://552555]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-04-20 11:10 GMT
Find Nodes?
    Voting Booth?