Permalink
Browse files

add modifytwo

  • Loading branch information...
1 parent 9b8cd64 commit 2d0a8425f2ac4215e736d12ec14dffc9af93d35c @simonmar committed Feb 26, 2013
Showing with 19 additions and 0 deletions.
  1. +1 −0 Makefile
  2. +13 −0 modifytwo.hs
  3. +5 −0 parconc-examples.cabal
View
@@ -177,6 +177,7 @@ test:
cd kmeans && ../dist/build/kmeans/kmeans seq
cd kmeans && ../dist/build/kmeans/kmeans strat 64 +RTS -N2
./dist/build/logger/logger
+ ./dist/build/modifytwo/modifytwo
./dist/build/mvar1/mvar1
./dist/build/mvar2/mvar2
if ! ./dist/build/mvar3/mvar3; then true; else false; fi
View
@@ -0,0 +1,13 @@
+import Control.Concurrent
+
+modifyTwo :: MVar a -> MVar b -> (a -> b -> IO (a,b)) -> IO ()
+modifyTwo ma mb f =
+ modifyMVar_ mb $ \b ->
+ modifyMVar ma $ \a -> f a b
+
+main = do
+ ma <- newMVar 'a'
+ mb <- newMVar 'b'
+ modifyTwo ma mb (\a b -> return (succ a, succ b))
+ readMVar ma >>= print
+ readMVar mb >>= print
View
@@ -135,6 +135,11 @@ executable geturls9
, HTTP ==4000.2.*
default-language: Haskell2010
+executable modifytwo
+ main-is: modifytwo.hs
+ build-depends: base >= 4.5 && < 4.7
+ default-language: Haskell2010
+
executable chan
main-is: chan.hs
build-depends: base >= 4.5 && < 4.7

0 comments on commit 2d0a842

Please sign in to comment.