Skip to content

Instantly share code, notes, and snippets.

@abbradar abbradar/test.hs
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.