[Haskell-cafe] Race Condition in threads

2012-12-18 Thread mukesh tiwari
Hello All I have two questions. 1. I wrote this code to create 10 simultaneous threads. Could some one please tell me if this is correct or not ? incr_count :: MVar () - MVar Int - IO () incr_count m n = ( forM_ [ 1..1 ] $ \_ - modifyMVar_ n ( return . ( + 10 ) ) ) putMVar m () main ::

Re: [Haskell-cafe] Race Condition in threads

2012-12-18 Thread Serguey Zefirov
2012/12/18 mukesh tiwari mukeshtiwari.ii...@gmail.com: Hello All I have two questions. 1. I wrote this code to create 10 simultaneous threads. Could some one please tell me if this is correct or not ? incr_count :: MVar () - MVar Int - IO () incr_count m n = ( forM_ [ 1..1 ] $ \_ -

Re: [Haskell-cafe] Race Condition in threads

2012-12-18 Thread mukesh tiwari
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 .. 1 ] $ \_ - writeIORef n 10 ) putMVar m () main :: IO ()