I recently upgraded to ghc 7.0.2 from 6.12.3, along with the Haskell platform, and noticed that the following code no longer works as expected:<br><br><span style="font-family: courier new,monospace;">waitFor tvar = atomically $ do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> count <- readTVar tvar</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> check (count == 0)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">worker tchan tvar = loop</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> where loop = do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> putStrLn "checking"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> finished <- atomically $ isEmptyTChan tchan</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> threadDelay 50000</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if finished</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> then atomically $ do val <- readTVar tvar</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> writeTVar tvar $ (subtract 1) val</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> else (atomically $ readTChan tchan) >> loop</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">test = do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> tchan <- newTChanIO</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> pure $ forM_ [1..5] $ writeTChan tchan</span> -- THIS LINE <br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> tvar <- newTVarIO 1</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> forkIO $ worker tchan tvar</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> waitFor tvar</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> putStrLn "DONE"</span><br><br>This will work if I use atomically, but otherwise it does nothing, tchan remains empty afterwards. <br>
I'm not clear how this should behave.<br><br>