IO and STM
Robert van Herk
rherk at cs.uu.nl
Wed Apr 13 12:30:09 EDT 2005
Hi all,
I have a question about IO in a STM transaction.
I want to make an atomic algorithm that does the following:
1. read an IORef
2. write some changes to the value you get from 1
3. save the IORef again
Currently, I did this, roughly like this:
doSomething :: IORef [s] -> s -> IO ()
doSomething ref s =
atomically (
do { ss <- unsafeIOToSTM (readIORef s);
do something with ss;
unsafeIOToSTM (writeIORef s ss);
return ()
}
)
Since I read that STM uses a revertable log, I was wondering what
happens with the IO actions, when a rerun on the atomic part is
performed... I guess it will just redo them? Is this the unsafe-part of
unsafeIOToSTM, or are there more caveats?
Regards,
Robert
More information about the Glasgow-haskell-users
mailing list