summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib/Concurrent/4876.hs
blob: 68c2a871b8e4cce169aab5bc9c901583775d002c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import System.Random
import Control.Concurrent.SampleVar
import Control.Concurrent
import Control.Monad

produce, consume :: SampleVar Int -> IO ()
produce svar = do
   b <- isEmptySampleVar svar
   if b then writeSampleVar svar 3 else return ()

consume svar = readSampleVar svar >>= print

main = do
   svar <- newEmptySampleVar
   m <- newEmptyMVar
   forkIO $ consume svar >> putMVar m ()
   threadDelay 100000     -- 100 ms
   produce svar
   takeMVar m -- deadlocked before the fix in #4876