STM and unsafePerformIO
Robert van Herk
rherk at cs.uu.nl
Wed Aug 3 07:09:00 EDT 2005
Oh I see! Your sollutions are indeed a lot better than implementating
all my code using MVars :-).
Remi Turk wrote:
>On Wed, Aug 03, 2005 at 12:50:54PM +0200, Robert van Herk wrote:
>>I think I've read somewhere that STM doesn't like unsafePerformIO.
>>However, I would like to use a global STM variable. Something like this:
>>module Main where
>>tSid = unsafePerformIO (atomically (newTVar 0))
>>tickSessionID :: STM Int
>> do sid <- readTVar tSid
>> writeTVar tSid (sid + 1)
>> return sid
>>main = atomically tickSessionID
>>But, when I try this, the evaluation of main causes a segmentation
>>fault. Is there a workaround for this bug?
>It probably dies not because of unsafePerformIO per se, but
>because STM doesn't understand nested transactions, and
>unsafePerformIO here results in a nested transaction. Using the
>following main works for me, as it forces both "atomically"'s to
>be evaluated sequentially:
>main = tSid `seq` atomically tickSessionID
>P.S. Could you find out (and fix) what inserts those spurious *'s in your code?
More information about the Glasgow-haskell-users