[Haskell-beginners] merge two handles

Manfred Lotz manfred.lotz at arcor.de
Wed Jun 15 17:15:35 CEST 2011


On Wed, 15 Jun 2011 10:33:21 -0400
David McBride <dmcbride at neondsl.com> wrote:

> The problem is the "forever" in the main thread.  It never has a way
> to know that the two threads have died, but the stm knows that the
> other two channels have disappeared, so they no longer block, and this
> causes a busy loop.
> 
> So check this out.  I would have rather done it with a state monad to
> count the number of threads I spawn and then wait for the appropriate
> number of messages to arrive, but this way works too.
> 
> This is one of those cases where datatypes are awesome.  Now the
> thread passes back either a line to be printed, or it tells the parent
> thread that it has nothing left to print.  That way the main thread
> knows exactly when to die.
> 

Thanks a lot. I will study your solution carefully.


> Also, if you are going to be making command line scripts, I highly
> recommend the cmdargs package on hackage, as it is pretty cool for
> doing commandline arguments in a safe way.
> 

Yes, you are right of course. But here I wanted to have just a minimal
example.



-- 
Manfred




More information about the Beginners mailing list