Inaccurate docs for atomically

Andrew Martin andrew.thaddeus at gmail.com
Sun Nov 12 17:48:54 UTC 2017


This code works, so I don't think that's the case either:

    import Control.Concurrent.STM
    import Data.IORef
    import System.IO.Unsafe

    main :: IO ()
    main = do
      ref <- newIORef (6 :: Int)
      i <- atomically $ do
        var <- newTVar (unsafePerformIO (readIORef ref))
        readTVar var
      print i

On Sun, Nov 12, 2017 at 11:28 AM, Henning Thielemann <
lemming at henning-thielemann.de> wrote:

>
> On Sun, 12 Nov 2017, Andrew Martin wrote:
>
> In the stm package, the docs for atomically read:
>>
>> > You cannot use 'atomically' inside an 'unsafePerformIO' or >
>> 'unsafeInterleaveIO'. Any attempt to do so will result in a runtime >
>> error.  (Reason: allowing this would effectively allow a transaction >
>> inside a transaction, depending on exactly when the thunk is > evaluated.)
>>
>
> I always thought that it would be the other way round, i.e. that you
> cannot call 'unsafePerformIO' inside an 'atomically'. Maybe I mixed
> something up.




-- 
-Andrew Thaddeus Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20171112/6db60e4a/attachment.html>


More information about the Libraries mailing list