44module Main (main ) where
55
66import Control.Concurrent.Class.MonadSTM
7- import Control.Monad (replicateM )
7+ import Control.Monad (replicateM , forever )
88import Control.Monad.Class.MonadAsync
99import Control.Monad.Class.MonadFork
1010import Control.Monad.Class.MonadSay
@@ -67,6 +67,9 @@ prop_timeout_fail = timeout 1 (threadDelay 2)
6767prop_timeout_succeed :: forall m . MonadTimer m => m (Maybe () )
6868prop_timeout_succeed = timeout 2 (threadDelay 1 )
6969
70+ prop_timeout_race :: forall m . MonadTimer m => m (Maybe () )
71+ prop_timeout_race = timeout 1 (threadDelay 1 )
72+
7073
7174--
7275-- threads, async
@@ -88,6 +91,13 @@ prop_async n = do
8891 )
8992 traverse_ wait threads
9093
94+ prop_threadDelay_bottleneck :: forall m . (MonadTimer m , MonadSay m )
95+ => m (Maybe () )
96+ prop_threadDelay_bottleneck =
97+ timeout 1000000 $ do
98+ forever $ do
99+ threadDelay 1
100+ say " "
91101
92102main :: IO ()
93103main = defaultMain
@@ -117,6 +127,8 @@ main = defaultMain
117127 whnf id (runSimOrThrow prop_timeout_fail)
118128 , bench " succeed" $
119129 whnf id (runSimOrThrow prop_timeout_succeed)
130+ , bench " race" $
131+ whnf id (runSimOrThrow prop_timeout_race)
120132 ]
121133 ]
122134 ,
@@ -127,6 +139,8 @@ main = defaultMain
127139 whnf id (runSimOrThrow (prop_async n))
128140 , bench " forkIO silent" $
129141 whnf id (runSimOrThrow (prop_threads n))
142+ , bench " threadDelay bottleneck silent" $
143+ whnf id (runSimOrThrow prop_threadDelay_bottleneck)
130144 , bench " async say" $
131145 nf id ( selectTraceEventsSay
132146 $ runSimTrace
@@ -135,6 +149,10 @@ main = defaultMain
135149 nf id ( selectTraceEventsSay
136150 $ runSimTrace
137151 $ prop_threads n)
152+ , bench " threadDelay bottleneck say" $
153+ nf id ( selectTraceEventsSay
154+ $ runSimTrace
155+ $ prop_threadDelay_bottleneck)
138156 ]
139157 , env (pure 250 ) $ \ n ->
140158 bgroup " 250"
0 commit comments