[Haskell-beginners] Thread Blocking

mukesh tiwari mukeshtiwari.iiitm at gmail.com
Tue Sep 4 20:54:30 CEST 2012


Hello All
I was going trough Real World Haskell and it says "If we try to put a value
into an MVar that is already full, our thread is put to sleep until another
thread takes the value out". I wrote a simple code to block main

import Data.List
import Control.Concurrent

fun m = do
   putMVar m 10
   return ()


main = do
  m <- newEmptyMVar
  forkIO $ fun m
  putMVar m 10
  return ()

What I am expecting that main should be blocked at least couple of times
but its behaving more deterministically.
[mukesh.tiwari@ Programming]$ ghc-7.4.1 -threaded -fforce-recomp
Concurrent.hs
[1 of 1] Compiling Main             ( Concurrent.hs, Concurrent.o )
Linking Concurrent ...
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$ ./Concurrent  +RTS -N2
[mukesh.tiwari@ Programming]$

I am expecting to get thread blocked indefinitely on MVar at least half the
time. Could some one please tell me why this deterministic behavior ?
Regards
Mukesh Tiwari
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120905/3a051faf/attachment.htm>


More information about the Beginners mailing list