in reply to Re^7: Exiting a script with an 'infinitely looping' thread
in thread Exiting a script with an 'infinitely looping' thread

I meant at the OS level. What you see is Perl's emulation of signals. And as there usually is with emulations, there are incompatibilities in the behaviour of the emulated signals. That it doesn't work in Windows has nothing to do with safe signals, and all to do with a flawed emulation of sleep.

Replies are listed 'Best First'.
Re^9: Exiting a script with an 'infinitely looping' thread
by BrowserUk (Patriarch) on Nov 24, 2008 at 17:42 UTC
    That it doesn't work in Windows has nothing to do with safe signals,...

    On no?

    Try this (on a Windows system and perl 5.8.x using a cmd.exe exe console and a standard 101-key ps2-compatible keyboard configured for UK, on a Monday in November; shortly after 5.00 pm with a tail wind and a little good luck...)

    C:\test>set PERL_SIGNALS=safe C:\test>perl -wle"$SIG{INT}=sub{exit}; sleep 100" Terminating on signal SIGBREAK(21) C:\test>set PERL_SIGNALS=unsafe C:\test>perl -wle"$SIG{INT}=sub{exit}; sleep 100"

    In the first case, ^C has no effect, hence the need for ^break (SIGBREAK).

    However, the second example (with set PERL_SIGNALS=unsafe) it responds to ^C immediately.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I know it works with unsafe signals. Never said it didn't. It's a workaround, but not the cause. The problem is that sleep is broken in Windows. It's not interrupted by signals as the documentation says it should be.
        I know it works with unsafe signals.

        sleep was interuptable before safe signals were introduced. sleep is interuptable if safe signals are disabled.

        Viz: the implementation of safe signals is the root cause of the problem (even if the fix is to modify the implementation of sleep), and my statement that: "Due to Perl "safe signals", sleep is an uninteruptable opcode." is correct.

        And all your noise in this thread amounts to nothing more than an addendum of "only under windows", which is redundant, as I was replying to the OP who must be using windows otherwise he wouldn't have encountered the problem.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.