Hi Serguey
Thank you for reply. I tried with IORef but I am missing a function which modify it.
In this case every thread just write value 10 to variable n.
incr_count :: MVar () -> IORef Int -> IO ()
incr_count m n = ( forM_ [ 1 .. 10000 ] $ \_ -> writeIORef n 10 ) >> putMVar m ()
main :: IO ()
main = do
count <- newIORef 0
list <- forM [1..10] $ \_ -> newEmptyMVar
forM_ list $ \var -> forkIO . incr_count var $ count
forM_ list $ \var -> takeMVar var
val <- readIORef count
print val
ghci>:t atomicModifyIORef
atomicModifyIORef :: IORef a -> (a -> (a, b)) -> IO b
ghci>:t readIORef
readIORef :: IORef a -> IO a
ghci>:t writeIORef
writeIORef :: IORef a -> a -> IO ()
I have atomicModifyIORef but it puts it into IO. I am missing some thing like this