Skip to content

Instantly share code, notes, and snippets.

@abbradar
Last active August 29, 2015 14:05
Show Gist options
  • Save abbradar/76dafcee1807c9c5ac4d to your computer and use it in GitHub Desktop.
Save abbradar/76dafcee1807c9c5ac4d to your computer and use it in GitHub Desktop.
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
#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;
}
#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