atMost in GHC.Event.PSQ causes seqfault or bus error

Kazu Yamamoto ( 山本和彦 ) kazu at iij.ad.jp
Sat Apr 27 08:24:12 CEST 2013


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