Skip to content

Instantly share code, notes, and snippets.

@kazu-yamamoto
Created February 28, 2014 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu-yamamoto/9266343 to your computer and use it in GitHub Desktop.
Save kazu-yamamoto/9266343 to your computer and use it in GitHub Desktop.
errno is Haskell thread local
{-# LANGUAGE ForeignFunctionInterface #-}
import Control.Concurrent
import Foreign.C.Types
import Foreign.C.Error
main :: IO ()
main = do
s <- c_socket 2 1 0
forkIO $ do
c_close s
putStrLn "a closed"
threadDelay 200000
Errno e <- getErrno
putStrLn $ "a " ++ show e
forkIO $ do
threadDelay 100000
c_close s
putStrLn "b closed"
Errno e <- getErrno
putStrLn $ "b " ++ show e
threadDelay 1000000
foreign import ccall unsafe "socket"
c_socket :: CInt -> CInt -> CInt -> IO CInt
foreign import ccall unsafe "close"
c_close :: CInt -> IO CInt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment