STM and unsafePerformIO

Robert van Herk rherk at cs.uu.nl
Wed Aug 3 06:50:54 EDT 2005


Hello All,

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*
import GHC.Conc
import System.IO.Unsafe

tSid = unsafePerformIO (atomically (newTVar 0))

tickSessionID :: STM Int
tickSessionID =
  *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?

Regards,
Robert


More information about the Glasgow-haskell-users mailing list