@@ -0,0 +1,30 @@
1+import Control.Concurrent (threadDelay, myThreadId)
2+import Control.Monad.IO.Class (liftIO)
3+import System.Random (randomIO)
4+import System.IO
5+import Control.Applicative
6+
7+import Strands
8+
9+main = wait $ threads 3 $ do
10+ liftIO $ hSetBuffering stdout LineBuffering
11+ mainThread <- liftIO myThreadId
12+ liftIO $ putStrLn $ "Main thread: " ++ show mainThread
13+
14+ eventA <|> eventB
15+
16+eventA = do
17+ x <- sample (randomIO :: IO Int) 1000000
18+ evThread <- liftIO myThreadId
19+ liftIO $ putStrLn $ "X Event thread: " ++ show evThread
20+ liftIO $ putStrLn $ "x = " ++ (show x)
21+ return x
22+
23+eventB = do
24+ y <- sample (randomIO :: IO Int) 1000000
25+
26+ -- liftIO $ threadDelay 10000000
27+ evThread <- liftIO myThreadId
28+ liftIO $ putStrLn $ "Y Event thread: " ++ show evThread
29+ liftIO $ putStrLn $ "y = " ++ (show y)
30+ return y