hi folks, i'm using ghc6 (apt-get install ghc6) on debian31. as far is i understand, the following program shouldn't crash. can somebody tell me why it does? thanks a lot. johannes. module Main(main) where import Control.Concurrent.STM import System.IO.Unsafe {-# NOINLINE a #-} a :: TMVar Int a = unsafePerformIO $ atomically $ newTMVar 123 main = do atomically $ takeTMVar a >>= putTMVar a ghc --make -fno-cse Test.hs -o test ./test Segmentation fault
On 7/11/06, Johannes Goetz <johago@web.de> wrote:
i'm using ghc6 (apt-get install ghc6) on debian31. as far is i understand, the following program shouldn't crash. can somebody tell me why it does? thanks a lot. johannes.
Because atomically doesn't like unsafePerformIO. For TVars there's newTVarIO, but I'm not sure about TMVars. -- Taral <taralx@gmail.com> "You can't prove anything." -- Gödel's Incompetence Theorem
On 7/12/06, Taral <taralx@gmail.com> wrote:
Because atomically doesn't like unsafePerformIO.
In more detail: "atomically" is not re-entrant. You could try something like: main = a `seq` do ... to make sure that you don't re-enter the STM subsystem and crash. -- Taral <taralx@gmail.com> "You can't prove anything." -- Gödel's Incompetence Theorem
participants (2)
-
Johannes Goetz -
Taral