#2363: getChar cannot be interrupted with -threaded
----------------------------+-----------------------------------------------
Reporter: simonmar | Owner:
Type: bug | Status: new
Priority: high | Milestone: 6.10 branch
Component: libraries/base | Version: 6.8.2
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: Unknown
Os: Unknown |
----------------------------+-----------------------------------------------
Comment (by simonmar):
Replying to [comment:1 judah]:
> I was the original reporter of this problem. I have worked around it by
rewriting `myGetChar`:
> {{{
> myGetChar mv = do
> Control.Concurrent.threadWaitRead System.Posix.IO.stdInput
> c <- getChar
> putMVar mv (Just c)
> }}}
That's ok, as long as another thread doesn't call getChar right after your
threadWaitRead, then your getChar will hang again (not likely, I imagine,
but I've trained myself to spot race conditions :-).
Another workaround is to put stdin into non-blocking mode,
{{{
import System.Posix
... setFdOption stdInput NonBlockingRead True
}}}
but then you risk problems that caused us to stop doing this in the first
place (#724).
> The problem with the original code was that `getChar` (and
`hWaitForInput`) wrap foreign calls, which block the subthread they're run
in and thus cannot be halted by `killThread`. In contrast,
`threadWaitRead` wraps a primop, so it does not have that problem.
Actually in the threaded RTS `threadWaitRead` is not a primop, it's a
communication with the IO manager thread.
> This workaround is OK for now, but in my opinion all of the IO functions
should be interruptible by default. (And `threadWaitRead` uses `Fd`
instead of `Handle` which is more convenient/portable.)
I'm surprised you think that FD is more portable. Windows doesn't have
FDs except in a compatibility layer.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2363#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs