On Wed, 2008-11-26 at 13:25 -0800, Ryan Ingram wrote: > In fact: > > > import Control.Concurrent.STM > > import Control.Concurrent.STM.TMVar > > > -- gets a value from one of a list of TMVars > > takeTMVars :: [TMVar a] -> STM (TMVar a, a) > > takeTMVars = foldr fetch retry where > > fetch v act = (takeTMVar v >>= \a -> return (v, a)) `orElse` act > > > -- puts the given value into exactly one of a list of TMVars > > putTMVars :: [TMVar a] -> a -> STM (TMVar a) > > putTMVars vs a = foldr put retry vs where > > put v act = (putTMVar v a >> return v) `orElse` act
Of course those are TMVars, using STM. So in STM it is easy, whereas with MVars it is a bit harder. Duncan _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
