summaryrefslogtreecommitdiff
path: root/testsuite/tests/concurrent/should_run/conc003.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/concurrent/should_run/conc003.hs')
-rw-r--r--testsuite/tests/concurrent/should_run/conc003.hs28
1 files changed, 28 insertions, 0 deletions
diff --git a/testsuite/tests/concurrent/should_run/conc003.hs b/testsuite/tests/concurrent/should_run/conc003.hs
new file mode 100644
index 0000000000..c7b1f9a56c
--- /dev/null
+++ b/testsuite/tests/concurrent/should_run/conc003.hs
@@ -0,0 +1,28 @@
+module Main where
+
+import Control.Concurrent
+
+-- simple handshaking using two MVars,
+-- must context switch twice for each character.
+
+main = do
+ ready <- newEmptyMVar
+ datum <- newEmptyMVar
+ let
+ reader = do
+ putMVar ready ()
+ char <- takeMVar datum
+ if (char == '\n')
+ then return ()
+ else do putChar char; reader
+
+ writer "" = do
+ takeMVar ready
+ putMVar datum '\n'
+ writer (c:cs) = do
+ takeMVar ready
+ putMVar datum c
+ writer cs
+
+ forkIO reader
+ writer "Hello World"