[GHC] #418: unsafeInterleaveIO + Ctrl-C/killThread related segfault

GHC trac at galois.com
Thu Jan 25 09:53:20 EST 2007


#418: unsafeInterleaveIO + Ctrl-C/killThread related segfault
----------------------------+-----------------------------------------------
 Reporter:  remit           |          Owner:  igloo  
     Type:  bug             |         Status:  new    
 Priority:  lowest          |      Milestone:         
Component:  Runtime System  |        Version:  6.4.1  
 Severity:  normal          |     Resolution:  None   
 Keywords:                  |     Difficulty:  Unknown
 Testcase:                  |   Architecture:  Unknown
       Os:  Unknown         |  
----------------------------+-----------------------------------------------
Changes (by igloo):

  * testcase:  =>
  * status:  assigned => new
  * owner:  nobody => igloo

Old description:

> {{{
> [copy-pasting my original mail
> (http://www.haskell.org/pipermail/glasgow-haskell-bugs/2005-
> June/005235.html)]
>
> Good evening,
>
> I just stumbled across a segfault caused when running the
> following small program. (During an attempt to implement
> single-assignment variables.)
>
> > module Main where
> >
> > import Control.Concurrent
> > import System.IO.Unsafe (unsafeInterleaveIO)
> >
> > main = do
> >     v <- newEmptyMVar
> >     a <- unsafeInterleaveIO (readMVar v)
> >     t <- forkIO (print a)
> >     threadDelay (1000*1000)
> >     killThread t
> >     forkIO (print a)
> >     putMVar v ()
>
> The crucial part about it seems to be the interruption
> of the
> lazy IO. Typing Ctl-c while running the first "print a"
> by hand
> from ghci instead of the forkIO+killThread doesn't change
> behaviour:
>
>  Prelude System.IO.Unsafe Control.Concurrent> v <-
> newEmptyMVar
>  Prelude System.IO.Unsafe Control.Concurrent> a <-
> unsafeInterleaveIO (readMVar v)
>  Prelude System.IO.Unsafe Control.Concurrent> print a
>  Interrupted.
>  Prelude System.IO.Unsafe Control.Concurrent> forkIO
> (print a)
>  Prelude System.IO.Unsafe Control.Concurrent> putMVar v ()
>  zsh: segmentation fault (core dumped)  ghci
>
> Both 6.4 and 6.2.1 crash when running main from ghci.
> When running it as a compiled executable everything is
> fine.
>
> Although I'm pretty sure I've seen 6.2.1 crashing
> on it when run with -e main, I cannot reproduce it
> anymore. 6.4
> certainly happily runs it with -e main. (A serious lack
> of sleep
> the last week may play a role too.. :-/)
>
> Whether the module is compiled before being loaded into
> ghci has
> no effect.
>
> Core-dumps etc can of course be sent if necessary.
>
> Good night,
> Remi
> }}}

New description:

 [copy-pasting my original mail
 (http://www.haskell.org/pipermail/glasgow-haskell-bugs/2005-
 June/005235.html)]

 Good evening,

 I just stumbled across a segfault caused when running the
 following small program. (During an attempt to implement
 single-assignment variables.)

 {{{
 > module Main where
 >
 > import Control.Concurrent
 > import System.IO.Unsafe (unsafeInterleaveIO)
 >
 > main = do
 >     v <- newEmptyMVar
 >     a <- unsafeInterleaveIO (readMVar v)
 >     t <- forkIO (print a)
 >     threadDelay (1000*1000)
 >     killThread t
 >     forkIO (print a)
 >     putMVar v ()
 }}}

 The crucial part about it seems to be the interruption
 of the
 lazy IO. Typing Ctl-c while running the first "print a"
 by hand
 from ghci instead of the forkIO+killThread doesn't change
 behaviour:

 {{{
  Prelude System.IO.Unsafe Control.Concurrent> v <- newEmptyMVar
  Prelude System.IO.Unsafe Control.Concurrent> a <- unsafeInterleaveIO
 (readMVar v)
  Prelude System.IO.Unsafe Control.Concurrent> print a
  Interrupted.
  Prelude System.IO.Unsafe Control.Concurrent> forkIO (print a)
  Prelude System.IO.Unsafe Control.Concurrent> putMVar v ()
  zsh: segmentation fault (core dumped)  ghci
 }}}

 Both 6.4 and 6.2.1 crash when running main from ghci.
 When running it as a compiled executable everything is
 fine.

 Although I'm pretty sure I've seen 6.2.1 crashing
 on it when run with -e main, I cannot reproduce it
 anymore. 6.4
 certainly happily runs it with -e main. (A serious lack
 of sleep
 the last week may play a role too.. :-/)

 Whether the module is compiled before being loaded into
 ghci has
 no effect.

 Core-dumps etc can of course be sent if necessary.

 Good night,
 Remi

Comment:

 This seems to be fixed in 6.6. Leaving it open to remind me to add the
 example to the testsuite.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/418>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list