Last active
August 29, 2015 14:05
-
-
Save abbradar/76dafcee1807c9c5ac4d to your computer and use it in GitHub Desktop.
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
import Text.Printf | |
import Control.Concurrent | |
import Control.Monad | |
import Control.Exception | |
foreign import ccall unsafe "test_c.h read_errno" get_errno :: IO Int | |
foreign import ccall unsafe "test_c.h write_errno" set_errno :: Int -> IO () | |
main :: IO () | |
main = do | |
forM_ [1..10000] $ \i -> do | |
forkIO $ forever $ mask_ $ do | |
set_errno i | |
r <- get_errno | |
when (i /= r) $ putStrLn $ printf "Awaited %d, got %d" i r | |
threadDelay maxBound |
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
#include "errno.h" | |
#include "test_c.h" | |
#define ERRNO my_errno | |
__thread int my_errno; | |
int read_errno(void) | |
{ | |
return ERRNO; | |
} | |
void write_errno(const int i) | |
{ | |
ERRNO = i; | |
} |
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
#ifndef TEST_H | |
#define TEST_H | |
int read_errno(void); | |
void write_errno(const int); | |
#endif // TEST_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment