[Haskell-cafe] STM, orElse and timed read from a channel

Tomasz Zielonka tomasz.zielonka at gmail.com
Mon Dec 5 04:50:20 EST 2005

On Mon, Dec 05, 2005 at 09:19:05AM -0000, Simon Peyton-Jones wrote:
> Can you provide a small test case that demonstrates the crash?

Here it is:

    import Control.Concurrent.STM
    import System.IO.Unsafe (unsafePerformIO)

    {-# NOINLINE var #-}
    var :: TVar ()
    var = unsafePerformIO (atomically (newTVar ()))

    main = atomically (readTVar var)

I remember someone else posted a crash example with unsafeInterleaveIO.

> I think it's pretty unlikely that we'll support nested atomically (via
> unsafePerformIO) anytime soon.

OK, it's fine with me.
But maybe it would be easy to raise an exception in such scenario?

> UnsafePerformIO is, well, unsafe.

And so is unsafeInterleaveIO.

> I think you are really asking for some way to create top-level
> transactional variables?

Yes. Perhaps it would be easier to do it cleanly than arbitrary
top-level IO bindings?

In fact, almost every time I wanted a top-level unpure thingy, it was a
concurrency variable.

Best regards

I am searching for a programmer who is good at least in some of
[Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland

More information about the Haskell-Cafe mailing list