Created
September 4, 2018 18:47
-
-
Save eborden/57dde013c9488e60bf37f234d415bc47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./take-throw-test.hs | |
with | |
m | |
... | |
with | |
m | |
with | |
m | |
with | |
m | |
with | |
m | |
with | |
take-throw-test.hs: user error (take and throw) | |
take-throw-test.hs: thread blocked indefinitely in an MVar operation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --install-ghc runghc --package exceptions | |
import Control.Concurrent (forkIO, threadDelay) | |
import Control.Concurrent.MVar (newMVar, withMVar, takeMVar) | |
import Control.Exception (throwIO) | |
import Control.Monad (forever) | |
import System.IO (BufferMode(LineBuffering), hSetBuffering, stdout) | |
main = do | |
hSetBuffering stdout LineBuffering | |
m <- newMVar "m" | |
forkIO $ do | |
threadDelay 10000 | |
takeMVar m | |
throwIO $ userError "take and throw" | |
forever $ do | |
putStrLn "with" | |
withMVar m putStrLn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also tested this with a "Russian Doll"
MVar
and GHC still catches it