Skip to content

Instantly share code, notes, and snippets.

@lkuper
Created October 19, 2014 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lkuper/29fab36b954acbf56d9c to your computer and use it in GitHub Desktop.
Save lkuper/29fab36b954acbf56d9c to your computer and use it in GitHub Desktop.
{-# 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