[Haskell-cafe] Re: how to implement daemon start and stop directives?

Luke Palmer lrpalmer at gmail.com
Thu Jan 22 07:58:11 EST 2009

On Thu, Jan 22, 2009 at 5:48 AM, Ertugrul Soeylemez <es at ertes.de> wrote:

> Luke Palmer <lrpalmer at gmail.com> wrote:
> > TVars are overkill here, actually, an IORef would be just fine, I
> > think.
> Using IORefs is generally a sign of bad style.

I totally disagree.

The disadvantage of IORefs is that they do not work together very nicely.
 If you have more than one, it is very hard (impossible) to keep
multithreaded invariants between them.

But in this case, the IORef is completely encapsulated: it does not leave
the scope in which it was created.  You will never have to use it with any
other IORef, because nobody else even knows it exists.  The pattern is
self-contained and threadsafe with just an IORef.

A program that needs only IORefs and is threadsafe is *good* style to me,
because it means all the state is well-encapsulated (if it escaped, it would
fail to be threadsafe).


>  But MVars would
> perfectly suffice here.  They would be essentially the same, but without
> 'atomically'.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090122/2e2a0af7/attachment.htm

More information about the Haskell-Cafe mailing list