Created
February 28, 2014 06:31
-
-
Save kazu-yamamoto/9266343 to your computer and use it in GitHub Desktop.
errno is Haskell thread local
This file contains 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
{-# 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