important news: refocusing discussion

Ross Paterson ross at soi.city.ac.uk
Tue Mar 28 05:28:51 EST 2006


On Tue, Mar 28, 2006 at 10:14:27AM +0100, Simon Marlow wrote:
> On 28 March 2006 00:24, Ross Paterson wrote:
> > As Malcolm pointed out, using MVars requires some care, even if you
> > were just aiming to be thread-safe.
> 
> I don't really understand the problem, maybe I'm missing something.  I
> thought the idea would be that a thread-safe library would simply use
> MVar instead of IORef.

MVars certainly require more care than IORefs: you have to ensure your
takes and puts are matched, for example.

And there's the possibility of deadlock when you have more than one
variable.  I was toying with an interface like

	newRef :: a -> IO (Ref a)
	modifyRef :: Ref a -> (a -> (a, r)) -> IO r
	modifyRef2 :: Ref a -> Ref b -> (a -> b -> (a, b, r)) -> IO r
	...

where Refs are MVars plus a stable ordering, so all the primitives
lock (i.e. take) them in the same order.  It's a bit clunky, though.

On Tue, Mar 28, 2006 at 10:25:04AM +0100, Simon Marlow wrote:
> It just occurred to me that STM isn't completely trivial in a
> single-threaded implementation, because exceptions have to abort a
> transaction in progress.

Ah, and it seemed so simple.  Still, exception-safety would be a nice
property for a state abstraction to have.



More information about the Haskell-prime mailing list