diff options
author | David Terei <davidterei@gmail.com> | 2011-07-20 11:09:03 -0700 |
---|---|---|
committer | David Terei <davidterei@gmail.com> | 2011-07-20 11:26:35 -0700 |
commit | 16514f272fb42af6e9c7674a9bd6c9dce369231f (patch) | |
tree | e4f332b45fe65e2a7a2451be5674f887b42bf199 /testsuite/tests/concurrent/should_run/conc039.hs | |
parent | ebd422aed41048476aa61dd4c520d43becd78682 (diff) | |
download | haskell-16514f272fb42af6e9c7674a9bd6c9dce369231f.tar.gz |
Move tests from tests/ghc-regress/* to just tests/*
Diffstat (limited to 'testsuite/tests/concurrent/should_run/conc039.hs')
-rw-r--r-- | testsuite/tests/concurrent/should_run/conc039.hs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/testsuite/tests/concurrent/should_run/conc039.hs b/testsuite/tests/concurrent/should_run/conc039.hs new file mode 100644 index 0000000000..dc5d181a31 --- /dev/null +++ b/testsuite/tests/concurrent/should_run/conc039.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE ForeignFunctionInterface #-} + +import Foreign +import System.Mem +import Control.Concurrent + +foreign export ccall "performGC_" performGC' :: IO () +performGC' = do putMVar m (); yield; performGC + +foreign import ccall "performGC_" f :: IO () + +{-# NOINLINE m #-} +m = unsafePerformIO newEmptyMVar + +main = do + forkIO f + takeMVar m + +-- This tests for a bug in the garbage collector, whereby a main +-- thread that has completed may be GC'd before its return value is +-- propagated back to the caller of rts_evalIO(). +-- +-- The sequence we hope to create is: +-- - main thread (1) forks off thread (2) +-- - thread (2) invokes new main thread (3) via a 'safe' ccall +-- - thread (3) yields to thread (1) +-- - thread (1) completes, but cannot return yet because (3) +-- is the current main thread (unless we +-- are in SMP or RTS_SUPPORTS_THREADS mode) +-- - thread (3) invokes a GC +-- - thread (1) is GC'd, unless we're careful! |