unsafeness of unsafeInterleaveIO

Remi Turk rturk at science.uva.nl
Fri Jun 10 21:23:25 EDT 2005


On Sat, Jun 11, 2005 at 01:55:57AM +0200, Thomas Jäger wrote:
> > Just looking at the documentation for System.IO.unsafeInterleaveIO,
> > what exactly is unsafe about it?
> 
> It can create "pure values" that trigger side effects during their
> evaluation. This can be abused to do IO outside of an IO monad
> (actually, hGetContents can already be used for that purpose).
> 
> In the worst case, it can even crash the RTS:
> > import Control.Concurrent.STM
> > import System.IO.Unsafe
> > 
> > main :: IO ()
> > main = atomically =<< unsafeInterleaveIO (atomically $ return $ return ())
> 
> Thomas

Stares at a core-dump.
I wonder whether this would be worth a bug-report, or perhaps a
warning in STM's docs about (understandable) undefined behaviour
in this case. Interestingly, Tomasz Zielonka's FakeSTM [1]
survives it.

Groeten,
Remi

[1]
	http://www.haskell.org/pipermail/haskell-cafe/2005-March/009389.html
	darcs get http://www.uncurry.com/repos/FakeSTM/

-- 
Nobody can be exactly like me. Even I have trouble doing it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/glasgow-haskell-users/attachments/20050611/6a532bca/attachment.bin


More information about the Glasgow-haskell-users mailing list