[project @ 1998-06-04 16:15:10 by simonm]
authorsimonm <unknown>
Thu, 4 Jun 1998 16:15:20 +0000 (16:15 +0000)
committersimonm <unknown>
Thu, 4 Jun 1998 16:15:20 +0000 (16:15 +0000)
Add a few simple concurrency tests.  More to come.

ghc/tests/concurrent/Makefile [new file with mode: 0644]
ghc/tests/concurrent/should_run/conc001.hs [new file with mode: 0644]
ghc/tests/concurrent/should_run/conc001.stdout [new file with mode: 0644]
ghc/tests/concurrent/should_run/conc002.hs [new file with mode: 0644]
ghc/tests/concurrent/should_run/conc002.stdout [new file with mode: 0644]
ghc/tests/concurrent/should_run/conc003.hs [new file with mode: 0644]
ghc/tests/concurrent/should_run/conc003.stdout [new file with mode: 0644]

diff --git a/ghc/tests/concurrent/Makefile b/ghc/tests/concurrent/Makefile
new file mode 100644 (file)
index 0000000..2d0e394
--- /dev/null
@@ -0,0 +1,11 @@
+#-----------------------------------------------------------------------------
+# $Id: Makefile,v 1.1 1998/06/04 16:15:10 simonm Exp $
+
+TOP = ..
+include $(TOP)/mk/boilerplate.mk
+
+SUBDIRS = should_run
+
+include $(TOP)/mk/target.mk
+
+
diff --git a/ghc/tests/concurrent/should_run/conc001.hs b/ghc/tests/concurrent/should_run/conc001.hs
new file mode 100644 (file)
index 0000000..8f7f3fe
--- /dev/null
@@ -0,0 +1,15 @@
+module Main where
+
+import Concurrent
+
+-- two processes, one MVar communication.
+
+main = do
+  s <- newEmptyMVar
+  let 
+    reader = do
+       str <- takeMVar s
+       putStr str
+
+  forkIO reader
+  putMVar s "hello world\n"
diff --git a/ghc/tests/concurrent/should_run/conc001.stdout b/ghc/tests/concurrent/should_run/conc001.stdout
new file mode 100644 (file)
index 0000000..3b18e51
--- /dev/null
@@ -0,0 +1 @@
+hello world
diff --git a/ghc/tests/concurrent/should_run/conc002.hs b/ghc/tests/concurrent/should_run/conc002.hs
new file mode 100644 (file)
index 0000000..4e876f8
--- /dev/null
@@ -0,0 +1,15 @@
+module Main where
+
+import Concurrent
+
+main = do
+  c <- newChan
+  let 
+    reader = do
+       char <- readChan c
+       if (char == '\n') 
+               then return () 
+               else do putChar char; reader    
+  forkIO reader
+  writeList2Chan c "Hello World\n"
+
diff --git a/ghc/tests/concurrent/should_run/conc002.stdout b/ghc/tests/concurrent/should_run/conc002.stdout
new file mode 100644 (file)
index 0000000..5e1c309
--- /dev/null
@@ -0,0 +1 @@
+Hello World
\ No newline at end of file
diff --git a/ghc/tests/concurrent/should_run/conc003.hs b/ghc/tests/concurrent/should_run/conc003.hs
new file mode 100644 (file)
index 0000000..dcd7222
--- /dev/null
@@ -0,0 +1,28 @@
+module Main where
+
+import 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"
diff --git a/ghc/tests/concurrent/should_run/conc003.stdout b/ghc/tests/concurrent/should_run/conc003.stdout
new file mode 100644 (file)
index 0000000..5e1c309
--- /dev/null
@@ -0,0 +1 @@
+Hello World
\ No newline at end of file