Created
October 19, 2014 01:41
-
-
Save lkuper/29fab36b954acbf56d9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
import Control.Concurrent (threadDelay) | |
import Control.LVish | |
import Control.LVish.DeepFrz | |
import Control.LVish.Internal (liftIO) | |
import Data.LVar.IVar | |
import Data.LVar.Counter | |
import Data.Word | |
lessthan :: (HasGet e, HasPut e, HasBump e) => Word -> Par e s (IVar s Bool) | |
lessthan w = do | |
r <- new | |
c <- newCounter 0 | |
fork $ (waitThresh c w >> put r True) | |
fork $ (doSomeWork c) | |
-- note that this is just `return r`, not `get r` | |
return r | |
doSomeWork c = do | |
liftIO $ threadDelay 1000000 | |
increment c 3 | |
main = do | |
let v = runParThenFreeze $ lessthan 4 | |
print $ case (fromIVar v) of | |
Nothing -> False | |
Just True -> True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment