Inaccurate docs for atomically

Jake McArthur jake.mcarthur at gmail.com
Sun Nov 12 19:19:53 UTC 2017


I think the point is that by using atomically inside unsafePerformIO you
risk using atomically inside atomically; that is, the bad case is
atomically inside unsafePerformIO inside atomically. The documentation is
wrong in that it only throws an exception when transactions are nested in
this way.

On Sun, Nov 12, 2017 at 12:48 PM, Andrew Martin <andrew.thaddeus at gmail.com>
wrote:

> 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
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20171112/17e97860/attachment.html>


More information about the Libraries mailing list