From 935b41c183bed01ce16913656db66cf847618389 Mon Sep 17 00:00:00 2001 From: Simon Marlow <marlowsd@gmail.com> Date: Thu, 8 Jul 2010 13:55:08 +0000 Subject: [PATCH] add TChan version of chan --- smp/chan/tchan.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 smp/chan/tchan.hs diff --git a/smp/chan/tchan.hs b/smp/chan/tchan.hs new file mode 100644 index 00000000..cddaf5b8 --- /dev/null +++ b/smp/chan/tchan.hs @@ -0,0 +1,22 @@ +-- benchmarks communication on TChan +-- +-- This is a synthetic benchmark that is sensitive to scheduler +-- behaviour. In GHC 6.12 and earlier we triggered a context switch +-- shortly after waking up a thread, whereas in 6.14 and later we +-- stopped doing that. This benchmark performs worse with 6.14 +-- becauuse not doing the context switch allows a lot of data to build +-- up in the Chan, making GC expensive. + +import Control.Concurrent +import Control.Concurrent.STM.TChan +import Control.Concurrent.STM +import System.Environment +import Control.Monad + +main = do + [n] <- fmap (fmap read) getArgs + c <- newTChanIO + m <- newEmptyMVar + a <- forkIO $ forM_ [1..n] $ \i -> atomically $ writeTChan c i + b <- forkIO $ do forM_ [1..n] $ \i -> atomically $ readTChan c; putMVar m () + takeMVar m -- GitLab