#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 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)
 }}}

 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.

 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.)

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2363#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to