mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-11-28 11:05:17 +03:00
62586627d8
This is an update of PR #540, thanks to @lodi
49 lines
980 B
Idris
49 lines
980 B
Idris
module Main
|
|
|
|
import System.Concurrency
|
|
|
|
child : Condition -> Mutex -> IO ()
|
|
child cond mtx = do
|
|
mutexAcquire mtx
|
|
str <- getThreadData String
|
|
putStrLn $ "child data: " ++ (show str)
|
|
|
|
setThreadData 17
|
|
i <- getThreadData Int
|
|
putStrLn $ "child data now: " ++ (show i)
|
|
|
|
conditionSignal cond
|
|
conditionWait cond mtx
|
|
|
|
putStrLn $ "child exiting"
|
|
|
|
conditionSignal cond
|
|
mutexRelease mtx
|
|
|
|
|
|
main : IO ()
|
|
main = do
|
|
setThreadData 13
|
|
i <- getThreadData Int
|
|
putStrLn $ "parent data initialized to: " ++ (show i)
|
|
|
|
setThreadData "hello"
|
|
str <- getThreadData String
|
|
putStrLn $ "parent data now: " ++ (show str)
|
|
|
|
mtx <- makeMutex
|
|
cond <- makeCondition
|
|
|
|
mutexAcquire mtx
|
|
_ <- fork (child cond mtx)
|
|
conditionWait cond mtx
|
|
|
|
str2 <- getThreadData String
|
|
putStrLn $ "parent data still: " ++ (show str2)
|
|
|
|
conditionSignal cond
|
|
conditionWait cond mtx
|
|
|
|
putStrLn $ "parent exiting"
|
|
mutexRelease mtx
|