Forked IORef reader function seems to stall main thread
问题 I was doing some experiments with concurrency and memory visibility and ran into this strange behavior (see comments inline): module Main where import Data.IORef import Control.Concurrent import System.CPUTime import System.IO main = do hSetBuffering stdout NoBuffering r <- newIORef False putStrLn "forking..." -- PRINTED forkIO $ f r threadDelay 1000000 putStrLn "writeIORef" -- NEVER PRINTED writeIORef r True threadDelay maxBound f :: IORef Bool -> IO () f r = readIORef r >>= \b-> if b then