atMost in GHC.Event.PSQ causes seqfault or bus error
Kazu Yamamoto ( 山本和彦 )
kazu at iij.ad.jp
Fri May 31 08:16:22 CEST 2013
Hi,
After a long fight, I found that this is a bug of the "-O2" option of
GHC head on 32bit machine. Now, it is easy to reproduce this
segfault. Please read and try this:
https://github.com/kazu-yamamoto/buggy-psq
Note that this segfault does not occur when "-O' is specified.
--Kazu
> Hi,
>
> threadDelay of GHC head causes seqfault or bus error on 32bit machine
> including Mac and Linux. This bug does not exist as least in GHC
> 7.4.2.
>
> This bug is due to atMost of GHC.Event.PSQ. After modifying
> libraries/base/base.cabal to export GHC.Event and building GHC head,
> the following code (compiled by the GHC head with -threaded) causes
> segfault or bus error:
>
> main :: IO ()
> main = do
> s <- newSource
> ents <- replicateM 100 (entry s)
> let q = fold ents
> print $ Q.atMost 1.5 q
>
> fold :: [(Q.Key, Q.Prio)] -> Q.PSQ ()
> fold [] = Q.empty
> fold ((u,r):xs) = Q.insert u r () $ fold xs
>
> entry :: UniqueSource -> IO (Q.Key, Q.Prio)
> entry s = do
> u <- newUnique s
> r <- randomIO
> return (u,r)
>
> But if I copy GHC.Event.PSQ and GHC.Event.Unique, modify their module
> names, and compile the above code with them, no segfault/bus error
> happens.
>
> I have been tracking this for a long time but I have no idea why this
> happens. Any advice would be highly appreciated.
>
> For more information, please refer to:
>
> http://hackage.haskell.org/trac/ghc/ticket/7715
>
> --Kazu
More information about the ghc-devs
mailing list