Inaccurate docs for atomically

Andrew Martin andrew.thaddeus at gmail.com
Mon Nov 13 02:44:38 UTC 2017


Thanks everyone for feedback on this. I’ve opened a PR at https://github.com/ghc/ghc/pull/87 and any commentary on the haddock changes there is appreciated.

Sent from my iPhone

> On Nov 12, 2017, at 11:17 AM, Andrew Martin <andrew.thaddeus at gmail.com> 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.)
> 
> This doesn't seem to be true. The following program runs fine:
> 
>     import Control.Monad.STM
>     import Control.Concurrent.STM.TVar
>     import System.IO.Unsafe
>     
>     main :: IO ()
>     main = do
>       v <- atomically $ newTVar (7 :: Int)
>       print $ unsafePerformIO $ atomically $ do
>         readTVar v
> 
> I suspect that the runtime only gives you an error if you actually create a nested transaction. Is my understanding correct?
> 
> -Andrew Thaddeus Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20171112/cb5f6c92/attachment.html>


More information about the Libraries mailing list