Created
February 8, 2011 22:10
-
-
Save softmechanics/817387 to your computer and use it in GitHub Desktop.
Illustrate Deadlock with Michael's Timeout module
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
import Control.Concurrent | |
import Control.Exception | |
import Control.Monad | |
import Network.Socket | |
import Timeout | |
main = do | |
mgr <- initialize 1 | |
forever $ do | |
threadDelay 10 | |
pair <- try $ socketPair AF_UNIX Stream defaultProtocol | |
case pair of | |
Left e -> do | |
let _ = e :: SomeException | |
print e | |
putStrLn "sleep" | |
threadDelay 100000 | |
Right (sock1, sock2) -> do | |
tid <- forkIO $ do | |
-- block until timeout | |
_ <- recv sock1 1 | |
return () | |
_ <- register mgr $ do | |
killThread tid | |
print sock1 | |
sClose sock1 | |
sClose sock2 | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment