summaryrefslogtreecommitdiff
path: root/testsuite/tests/concurrent/should_run/conc007.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/concurrent/should_run/conc007.hs')
-rw-r--r--testsuite/tests/concurrent/should_run/conc007.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/testsuite/tests/concurrent/should_run/conc007.hs b/testsuite/tests/concurrent/should_run/conc007.hs
new file mode 100644
index 0000000000..74535ebe6d
--- /dev/null
+++ b/testsuite/tests/concurrent/should_run/conc007.hs
@@ -0,0 +1,23 @@
+
+module Main where
+
+import Control.Concurrent
+import Control.Exception as E
+
+choose :: a -> a -> IO a
+choose a b = do
+ ready <- newMVar ()
+ answer <- newEmptyMVar
+ a_id <- forkIO (a `seq` takeMVar ready >> putMVar answer a)
+ b_id <- forkIO (b `seq` takeMVar ready >> putMVar answer b)
+ it <- takeMVar answer
+ killThread a_id
+ killThread b_id
+ return it
+
+main = do
+ let big = sum [1..]
+ small = sum [1..42]
+ test1 <- choose big small
+ test2 <- choose small big
+ print (test1,test2)