summaryrefslogtreecommitdiff
path: root/testsuite/tests/concurrent/should_run/tryReadMVar2.hs
blob: 13b8a45c320cbbe5dabbd6150b6bb205ed1b2cff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Main where

import Control.Concurrent
import Control.Monad

main = do
    m <- newEmptyMVar
    done <- newEmptyMVar
    let q = 200000
    forkIO (do mapM (\n -> putMVar m n) [1..q]; putMVar done ())
    forkIO (do replicateM_ q $ readMVar m; putMVar done ())
    forkIO (do replicateM_ q $ tryReadMVar m; putMVar done ())
    forkIO (do replicateM_ q $ takeMVar m; putMVar done ())
    replicateM_ 4 $ takeMVar done