Commit 81296527 authored by Simon Marlow's avatar Simon Marlow
Browse files

Remove the reliance on relative accuracy of short delays (#7656)

parent 49cb749d
......@@ -2,6 +2,7 @@
import Control.Concurrent
import Control.Exception
import Control.Monad
import Data.List
new = newQSemN
wait = waitQSemN
......@@ -52,33 +53,33 @@ semn2 :: Assertion
semn2 = do
c <- newEmptyMVar
q <- new 0
t1 <- forkIO $ do wait q 1; threadDelay 10000; putMVar c 'a'
t1 <- forkIO $ do wait q 1; putMVar c 'a'
threadDelay 10000
t2 <- forkIO $ do wait q 2; threadDelay 20000; putMVar c 'b'
t2 <- forkIO $ do wait q 2; putMVar c 'b'
threadDelay 10000
t3 <- forkIO $ do wait q 3; threadDelay 30000; putMVar c 'c'
t3 <- forkIO $ do wait q 3; putMVar c 'c'
threadDelay 10000
signal q 6
a <- takeMVar c
b <- takeMVar c
c <- takeMVar c
[a,b,c] @?= "abc"
sort [a,b,c] @?= "abc"
semn3 :: Assertion
semn3 = do
c <- newEmptyMVar
q <- new 0
t1 <- forkIO $ do wait q 1; threadDelay 10000; putMVar c 'a'
t1 <- forkIO $ do wait q 1; putMVar c 'a'
threadDelay 10000
t2 <- forkIO $ do wait q 2; threadDelay 20000; putMVar c 'b'
t2 <- forkIO $ do wait q 2; putMVar c 'b'
threadDelay 10000
t3 <- forkIO $ do wait q 3; threadDelay 30000; putMVar c 'c'
t3 <- forkIO $ do wait q 3; putMVar c 'c'
threadDelay 10000
signal q 3
a <- takeMVar c
b <- takeMVar c
threadDelay 10000
[a,b] @?= "ab"
sort [a,b] @?= "ab"
d <- isEmptyMVar c
d @?= True
signal q 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment