[Haskell-cafe] Re: Is my code too complicated?

Ertugrul Soeylemez es at ertes.de
Mon Jul 5 09:29:44 EDT 2010

Felipe Lessa <felipe.lessa at gmail.com> wrote:

> On Mon, Jul 5, 2010 at 6:12 AM, Ertugrul Soeylemez <es at ertes.de> wrote:
> > Felipe Lessa <felipe.lessa at gmail.com> wrote:
> >
> >> On Sat, Jul 3, 2010 at 9:25 AM, Ertugrul Soeylemez <es at ertes.de> wrote:
> >>> Haskell provides a lot of low level glue like laziness, currying
> >>> and other very helpful language features.  But what is different
> >>> in Haskell is that it doesn't seem to provide any high level glue
> >>> like other languages do, especially when it comes to the IO
> >>> world.  There is a somewhat powerful module system, but nothing to
> >>> bring modules and the objects they define together in a consistent
> >>> way.
> >>
> >> When I first read this paragraph, I thought: "STM to the rescue!".
> >> STM is one of the best concurrent world glues, IMHO.
> >
> > I found that I get along with the basic concurrency constructs.  STM
> > may be handy in a few applications, but in none that I write.
> STM has the same basic concurrency constructs, but they are safe to
> use.  MVars and everything derived from them have tricky semantics
> that can fail in catastrofic ways.  Neil Mitchell was recently trying
> to find a subtle bug in his code because of MVars and Chans.

It happened once to me that I forgot that MVars don't have a queue.  A
database thread would take values out of the MVar as commands and
execute them, but I used the same thread to put a command into the MVar
(for later execution).  It worked most of the time, unless another
thread put a command concurrently, right after the last command was
executed and before the database thread put another command ⇒ deadlock.

I fixed this by replacing the MVar by a Chan.  Could STM have helped
here?  And as a related question, how fast does STM perform in average?
Is it suitable for high traffic applications (not network/file traffic,
but MVar/Chan traffic)?  Usually in a non-SMP setting I can easily pass
hundreds of thousands of values per second through MVars between tens of
thousands of threads.


nightmare = unsafePerformIO (getWrongWife >>= sex)

More information about the Haskell-Cafe mailing list