2007-04-08 旧作。原载:http://blog.csdn.net/st_monad/article/details/1556189
一个线程发消息,一个线程收消息,重复很多遍。
import Control.Concurrent
main = do
m <- newEmptyMVar
end <- newEmptyMVar
forkIO (sequence_ [ putMVar m () | _ <- [1 .. 10000000] ])
forkIO (sequence_ [ takeMVar m | _ <- [1 .. 10000000] ] >> putMVar end ())
takeMVar end
zz from newsmth FuncProg faint.
import Control.Concurrent
main = do
m <- newEmptyMVar
end <- newEmptyMVar
forkIO (sequence_ [ putMVar m () | _ <- [1 .. 10000000] ])
forkIO (sequence_ [ takeMVar m | _ <- [1 .. 10000000] ] >> putMVar end ())
takeMVar end
zz from newsmth FuncProg faint.