Is this a concurrency bug in base?

Jean-Marie Gaillourdet jmg at
Sun Oct 9 13:52:47 CEST 2011


I am working on a library I'd like to release to hackage very soon, but I've found a problem with supporting GHC 6.12 and GHC 7.0.
Consider the following program: 

import Control.Concurrent
import Data.Typeable

main :: IO ()
main =
 do { fin1 <- newEmptyMVar
    ; fin2 <- newEmptyMVar

    ; forkIO $ typeRepKey (typeOf ()) >>= print >> putMVar fin1 ()
    ; forkIO $ typeRepKey (typeOf ()) >>= print >> putMVar fin2 ()

    ; () <- takeMVar fin1
    ; () <- takeMVar fin2
    ; putStrLn "---"
    ; return ()

When compiled with GHC 7.0.x or GHC 6.12.x, it should print two identical numbers. Sometimes it does not. 
To reproduce this compile and execute as follows:

$ ghc-7.0.3 -rtsopts -threaded TypeRepKey.hs -o TypeRepKey
$ while true ; do ./TypeRepKey +RTS -N  ; done

Ideally you should get an infinite number of zeros but once in a while you have a single(!) one in between. The two numbers of one program run should be identical, but their values may be arbitrary. But it should not be possible to have single outliers.

This only happens when executed with more than one thread. I've also a somewhat larger program which seems to indicate that fromDynamic fails occasionally. I can post it as well if it helps. This seems to be a Heisenbug as it is extremely fragile, when adding a "| grep 1" to the while loop it seems to disappears. At least on my computers. 

All this was done on several Macs running the latest OS X Lion with ghc 7.0.3 from the binary distribution on the GHC download page. 

Actually, I am trying to find a method to use a "type" as key in a map which works before GHC 7.2. I'd be glad to get any ideas on how to achieve that, given that typeRepKey seems to buggy. 

 I'd be happy to get any comments on this matter. 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: TypeRepKey.hs
Type: application/octet-stream
Size: 353 bytes
Desc: not available
URL: <>

More information about the Glasgow-haskell-users mailing list