blob: 74535ebe6d2dc0a99cfe7e5e1bd47a0301c0ae0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
module Main where
import Control.Concurrent
import Control.Exception as E
choose :: a -> a -> IO a
choose a b = do
ready <- newMVar ()
answer <- newEmptyMVar
a_id <- forkIO (a `seq` takeMVar ready >> putMVar answer a)
b_id <- forkIO (b `seq` takeMVar ready >> putMVar answer b)
it <- takeMVar answer
killThread a_id
killThread b_id
return it
main = do
let big = sum [1..]
small = sum [1..42]
test1 <- choose big small
test2 <- choose small big
print (test1,test2)
|