blocking parallel program

Facundo Domínguez facundo.dominguez at parsci.com
Sat Oct 19 22:19:22 UTC 2013


Hello,
   Below is a program that seems to block indefinitely with ghc in a
multicore machine. This program has a loop that does not produce
allocations, and I understand that this may grab one of the cores. The
question is, why can't the other cores take the blocked thread?

The program was compiled with:

$ ghc --make -O -threaded test.hs

and it is run with:

$ ./test

Program text follows.

Thanks,
Facundo

--------

import Control.Concurrent
import Control.Monad
import System.Environment

main :: IO ()
main = do
  y <- getArgs
  mv0 <- newEmptyMVar
  mv1 <- newEmptyMVar
  forkIO $ do
    takeMVar mv0
    putMVar mv1 ()
    loop (y == ["yield"])
  putMVar mv0 ()
  takeMVar mv1

loop :: Bool -> IO ()
loop cooperative = go
  where
    go = when cooperative yield >> go


More information about the Glasgow-haskell-users mailing list