[Haskell-cafe] Lock-Free Data Structures using STMs in Haskell

Bryan O'Sullivan bos at serpentine.com
Wed Apr 9 11:47:46 EDT 2008


Pete Kazmier wrote:

>   data ArrayBlockingQueueSTM e = ArrayBlockingQueueSTM {
>     [...]
>     sa :: Array Int (TVar e)
>   }
> 
> It's unclear to me why the Array's elements must be wrapped in TVars.

To allow them to be modified.  You can't otherwise modify the elements
of an array without going into the ST monad.

>   decPair v1 v1 :: TVar Int -> TVar Int -> IO ()
>   decPair v1 v2 = atomically (decT v1 `orElse` decT v2)
> 
> Will this actually compile?  I was under the impression that 'orElse'
> could only combine STM types, not IO () types.  

The type of atomically is STM a -> IO a.

	<b


More information about the Haskell-Cafe mailing list