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
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to