[GHC] #8502: Document a surprising {{{unsafeDupablePerformIO}}} limitation.
GHC
ghc-devs at haskell.org
Mon Nov 4 15:10:52 UTC 2013
#8502: Document a surprising {{{unsafeDupablePerformIO}}} limitation.
-------------------------------------+-------------------------------------
Reporter: int-e | Owner:
Type: task | Status: new
Priority: normal | Milestone: 7.8.1
Component: libraries/base | Version: 7.6.3
Keywords: | Operating System: Unknown/Multiple
Architecture: Unknown/Multiple | Type of failure: Documentation
Difficulty: Easy (less than 1 | bug
hour) | Test Case:
Blocked By: | Blocking:
Related Tickets: |
-------------------------------------+-------------------------------------
We just discussed the following code on #ghc.
{{{
import System.IO.Unsafe
import Control.Concurrent.MVar
import Control.Concurrent
import GHC.Conc (par, pseq)
x :: MVar Int -> Int -> Int
x m a = unsafeDupablePerformIO $
withMVar m $ \i -> do
sum [1..1000000 + a] `seq` return i
main1 = do
m <- newMVar 42
let w = x m 0
w `par` print w
{-
spark: thread blocked indefinitely in an MVar operation
-}
main2 = do
m <- newMVar 42
let w = x m 0
forkIO $ print w
forkIO $ print w
print w
{-
spark: <<loop>>
spark: <<loop>>
-}
main = main2
}}}
This is not a bug; what happens is that the RTS suspends one of the
duplicated computations of {{{w}}}, effectively killing the IO action that
was passed to {{{unsafeDupablePerformIO}}} in the middle. This limitation
of {{{unsafeDupablePerformIO}}} should be documented.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8502>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list