[project @ 2000-05-15 11:38:55 by simonmar]
[ghc-hetmet.git] / ghc / tests / concurrent / should_run / conc003.hs
1 module Main where
2
3 import Concurrent
4
5 -- simple handshaking using two MVars, 
6 -- must context switch twice for each character.
7
8 main = do
9   ready <- newEmptyMVar
10   datum <- newEmptyMVar
11   let 
12     reader = do
13         putMVar ready ()
14         char <- takeMVar datum
15         if (char == '\n') 
16                 then return () 
17                 else do putChar char; reader
18
19     writer "" = do
20         takeMVar ready
21         putMVar datum '\n'
22     writer (c:cs) = do
23         takeMVar ready
24         putMVar datum c
25         writer cs
26
27   forkIO reader
28   writer "Hello World"