[Haskell-cafe] Non-strict evaluation and concurrency (STM) : conflict?

2010-09-28 Thread Romain Demeyer
Hi, I'm working on Concurrent Haskell, especially with the monad STM. I don't fully understand the way my program is executed. I think the lazy evaluation leads to a loss of performance, if we don't pay attention to this problem. A short example will be more explicit : Imagine this scenario : we

Re: [Haskell-cafe] Non-strict evaluation and concurrency (STM) : conflict?

2010-09-28 Thread Edward Z. Yang
Excerpts from Romain Demeyer's message of Tue Sep 28 09:06:53 -0400 2010: That's what we want, but what is the explanation of this behavior? STM is designed to be optimistic, not blocking. So, does it means that the value is evaluated at commit-time? Do you know some problems that are related

Re: [Haskell-cafe] Non-strict evaluation and concurrency (STM) : conflict?

2010-09-28 Thread Felipe Lessa
On Tue, Sep 28, 2010 at 10:06 AM, Romain Demeyer romain.deme...@gmail.com wrote: Let's a function do_job, the function to execute by the threads (the workers) : do_job :: (b - a) - b - Inbox a - IO () do_job f input inbox = do { value - return (f input)                           ; atomically

Re: [Haskell-cafe] Non-strict evaluation and concurrency (STM) : conflict?

2010-09-28 Thread Romain Demeyer
Thanks for your help. It's more clear now. The value is not being evaluated by STM at all, as your STM functions don't need the value. In your program is evaluating when you print the answer in the main thread, as printing requires the value of the computation. If you didn't print, nothing

Re: [Haskell-cafe] Non-strict evaluation and concurrency (STM) : conflict?

2010-09-28 Thread Felipe Lessa
On Tue, Sep 28, 2010 at 11:38 AM, Romain Demeyer romain.deme...@gmail.com wrote: Does it means that the value is computed by the caller, based on the thunk, and not by the worker itself? It is computed by the one who needs the value. Your worker doesn't. Note that the value is computed on