[Haskell-cafe] Threads and hGetLine

Alvaro Gutierrez radical at google.com
Sun Apr 29 00:58:50 CEST 2012

Hi --

I am not well-versed in Haskell-specific multi-threading, but usually there
is a better way to do what you want that does not involve killing threads
(which in most cases is bad idea.)

For example, using non-blocking IO and e.g. a synchronized condition
variable; hWaitForInput might work in your case, or something like the
following: http://hpaste.org/52742

Nevertheless, as a guess, I think you may want to try using closeFdWith,
perhaps combined with a call to threadWaitRead before actually calling
hGetLine. The wrinkle is that those operate on file descriptors instead of
handles, but there are fdToHandle/mkHandleFromFD to bridge the gap.

Hope that helps,

On Sat, Apr 28, 2012 at 2:23 PM, H. M. <h._h._h._ at hotmail.com> wrote:

> Hello,
> The simplified problem:
> There are two threads, one which is waits on input via
> hGetLine
> and another, which should terminate this thread or close this handle.
> hClose
> as well as
> killThread
> doesn't seem to work, caused by the fact, that the thread is blocked until
> input
> is availiable.
> Hopefully you have some solution how to kill the thread and/or close the
> handle
> and/or have some other idea to get the lined input in the other thread.
> --
> Thanks in advance
> H.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120428/d2026f9e/attachment.htm>

More information about the Haskell-Cafe mailing list