Test for #7815
authorRyan Yates <ryates@cs.rochester.edu>
Tue, 9 Apr 2013 01:45:22 +0000 (21:45 -0400)
committerIan Lynagh <ian@well-typed.com>
Wed, 17 Apr 2013 19:41:45 +0000 (20:41 +0100)
This test differes slightly from the code in the ticket, but the
simplification betters the chances of seeing the error.  Instead of
looking for the error with an additional tranaction, when error appears
only one `reset` can complete and the other is blocked on STM raising an
exception.

testsuite/tests/rts/T7815.hs [new file with mode: 0644]
testsuite/tests/rts/all.T

diff --git a/testsuite/tests/rts/T7815.hs b/testsuite/tests/rts/T7815.hs
new file mode 100644 (file)
index 0000000..2710da1
--- /dev/null
@@ -0,0 +1,29 @@
+import GHC.Conc.Sync
+import Control.Monad
+import System.Environment
+
+test n = do
+  dog <- newTVarIO False
+  cat <- newTVarIO False
+  let unset = do
+        d <- readTVar dog
+        c <- readTVar cat
+        if (d || c) then retry else return ()
+      setDog = unset >> writeTVar dog True
+      setCat = unset >> writeTVar cat True
+      reset = do
+        d <- readTVar dog
+        c <- readTVar cat
+        guard (d || c)
+        writeTVar dog False
+        writeTVar cat False
+  
+  replicateM_ n (do
+    forkIO (atomically setDog)
+    forkIO (atomically setCat)
+    atomically reset
+    atomically reset)
+
+main = do
+  [n] <- getArgs
+  test (read n :: Int)
index 3a73054..f345b3b 100644 (file)
@@ -165,3 +165,8 @@ test('T7636', [ exit_code(1), extra_run_opts('100000') ], compile_and_run, ['']
 test('stablename001', expect_fail_for(['hpc']), compile_and_run, [''])
 # hpc should fail this, because it tags every variable occurrence with
 # a different tick.  It's probably a bug if it works, hence expect_fail.
+
+# Run this test alone (via, high_memory_usage) to increase chances of seeing the race.
+test('T7815', [ high_memory_usage,
+                extra_run_opts('50000 +RTS -N2 -RTS'),
+                only_ways(['threaded1', 'threaded2']) ], compile_and_run, [''] )