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

Chris Smith cdsmith at twu.net
Thu Apr 24 09:32:59 EDT 2008


On Thu, 24 Apr 2008 12:57:56 +0200, apfelmus wrote:
> there is also the option of collapsing  ReadOnlySTM a  and  STM a
> by changing the semantics of  writeTVar .
> 
> I mean,  writeTVar  can be used for two different things:
> 
>    1) communicate with other threads, i.e. crossing
>         atomically  boundaries
>    2) communicating inside a single thread/STM action
>       à la mutable state (IORef).
> 
> We only want 1), but 2) is expendable, we can always use parameters to
> pass state around or wrap the whole thing into a state monad. For 1),
> it's enough to have a primitive
> 
>    scheduleWriteTVar :: TVar a -> a -> STM ()
> 
> that ensures to write the TVar at the very end of the  atomically block.

Unfortunately, though, this breaks the very thing that makes STM 
attractive: namely, composability.  Now in order to work with a TVar, I 
need to know whether anything that came before me might have modified it, 
and if so take the current value as a parameter instead of reading it 
like normal.

Or am I misunderstanding something?

-- 
Chris Smith



More information about the Haskell-Cafe mailing list