[GHC] #3081: Double output after Ctrl+C on Windows
GHC
trac at galois.com
Thu Mar 12 06:16:20 EDT 2009
#3081: Double output after Ctrl+C on Windows
-------------------------------+--------------------------------------------
Reporter: NeilMitchell | Owner: simonmar
Type: bug | Status: new
Priority: normal | Milestone: _|_
Component: Runtime System | Version: 6.10.1
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Os: Windows
Architecture: x86 |
-------------------------------+--------------------------------------------
Changes (by simonmar):
* summary: Finally run twice on Ctrl+C => Double output after Ctrl+C on
Windows
* milestone: 6.10.2 => _|_
Comment:
Ok, this was an interesting one. In fact it has nothing to do with
`finally`; the following program has the same behaviour:
{{{
import System.Cmd
main = system "sleep 1m" >> putStrLn "goodbye"
}}}
In fact it even crashed with the HEAD, but the crash was particularly
fragile and most attempts to investigate it made it go away. This patch
fixes the crash:
{{{
Wed Mar 11 08:45:59 PDT 2009 Simon Marlow <marlowsd at gmail.com>
* avoid a crash: don't return unless the run queue has some threads in
it
}}}
which Ian has already merged.
However, the double-output problem still happens. It doesn't happen if
you use `-threaded`. Here's what's going on:
* When the user hits `^C`, the `system` call immediately returns.
* The RTS spins up a thread to throw the `^C` exception to the main
thread
* The main thread calls `putStrLn "goodbye"`
* The async IO system in the non-threaded RTS creates an OS thread to do
`write(1,"goodbye\n")`, and the main thread is blocked waiting for it to
complete
* the write completes
* The main thread receives the `Interrupted` exception. We try to abort
the IO,
but it has already happened.
* The top-level exception handler in the main thread flushes stdout. The
stdout
buffer still contains "goodbye", because the first IO was interrupted,
so it
writes that to stdout.
I don't think there's a way to fix this without serious surgery - we'd
need a way to synchronously abandon an async IO request, and I don't even
know if that's possible. I'll leave the bug at _|_ since it still exists,
but I doubt I'll fix it. If anyone else wants to try you're more than
welcome!
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3081#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list