
Felipe Lessa
On Mon, Jul 5, 2010 at 6:12 AM, Ertugrul Soeylemez
wrote: Felipe Lessa
wrote: On Sat, Jul 3, 2010 at 9:25 AM, Ertugrul Soeylemez
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. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/