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

Felipe Lessa felipe.lessa at gmail.com
Mon Jul 5 14:35:38 EDT 2010

On Mon, Jul 5, 2010 at 10:29 AM, Ertugrul Soeylemez <es at ertes.de> wrote:
> 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?

Probably only if both "puts" were in the same transaction, I guess.
Even with STM the solution is a channel, i.e. TChan.

> 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.

As always, I guess you should benchmark :).  There is some overhead,
indeed, however for most applications I guess it should be fine.
Specially because that overhead comes to save you from a lot of



More information about the Haskell-Cafe mailing list