[Haskell-cafe] Stronger STM primitives needed? Or am I just doing it wrong?

Ryan Ingram ryani.spam at gmail.com
Wed Apr 23 12:13:14 EDT 2008


On Wed, Apr 23, 2008 at 7:54 AM, Tim Harris (RESEARCH)
<tharris at microsoft.com> wrote:
>  What do you think about a slight change:
>
>    readTVarWhen :: TVar a -> (a -> bool) -> STM a

This seems strictly less powerful than retryUntil:
> readTVarWhen v p = retryUntil v p >> readTVar v

Consider the following transaction:

> intV :: TVar Int
> boolV :: TVar Bool
>
> interesting = atomically $ do
>    retryUntil intV (> 50)
>    retryUntil boolV id

Lets say that intV contains 100 and boolV contains False.  Then this
transaction retries.  Now, if intV changes to 101, this transaction
doesn't need to re-run; we can see immediately that no predicate
changed.  Using "readTVarWhen", this is less clear; the transaction
log would hold a read on intV which would be more difficult to ignore.

  -- ryan


More information about the Haskell-Cafe mailing list