Skip to content

Instantly share code, notes, and snippets.

@softmechanics
Created February 8, 2011 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save softmechanics/817387 to your computer and use it in GitHub Desktop.
Save softmechanics/817387 to your computer and use it in GitHub Desktop.
Illustrate Deadlock with Michael's Timeout module
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