Commit d8b1626f authored by Edward Z. Yang's avatar Edward Z. Yang

Tests for atomicReadMVar.

Signed-off-by: Edward Z. Yang's avatarEdward Z. Yang <ezyang@mit.edu>
parent 5bd8743f
......@@ -74,6 +74,10 @@ test('T5611', normal, compile_and_run, [''])
test('T5238', normal, compile_and_run, [''])
test('T5866', exit_code(1), compile_and_run, [''])
test('atomicReadMVar1', normal, compile_and_run, [''])
test('atomicReadMVar2', normal, compile_and_run, [''])
test('atomicReadMVar3', normal, compile_and_run, [''])
# -----------------------------------------------------------------------------
# These tests we only do for a full run
......
module Main where
import GHC.MVar
import Control.Concurrent
main = do
let i = 1000000
m <- newMVar (0 :: Int)
let readloop 0 = return ()
readloop i = do
atomicReadMVar m
readloop (i-1)
writeloop 0 = return ()
writeloop i = do
readMVar m
writeloop (i-1)
forkIO $ readloop i
writeloop i
module Main where
import GHC.MVar
import Control.Concurrent
main = do
m <- newEmptyMVar
sync <- newEmptyMVar
let f = atomicReadMVar m
t1 <- forkIO (f >> error "FAILURE")
t2 <- forkIO (f >> putMVar sync ())
killThread t1
putMVar m (0 :: Int)
atomicReadMVar sync
module Main where
import GHC.MVar
import Control.Concurrent
-- example from
-- http://www.haskell.org/pipermail/glasgow-haskell-users/2008-November/015878.html
main = do
m <- newMVar (0 :: Int)
forkIO $ putMVar m 1
yield
r1 <- atomicReadMVar m
r2 <- takeMVar m
r3 <- takeMVar m
return ()
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