views:

70

answers:

1

This is entirely theoretical at this point, but I've been trying to wrap my head around this problem. Let's take a client for an example. There are forkIOd threads for every connection, and one of them wants to quit the entire program (ie. /exit). How would this information be propagated to other threads?

This is not a condition, but I assume that the threads are reading from their respective threads which are blocking. Since they're idling away until something is written for them, they can't poll any kind of "done" variable. So my first thought unless done is bunked.

I don't have a solution in mind for any program, so anyone giving solutions for any language is appreciated, but the real question is how to do it in Haskell.

+7  A: 

The best way I know of is poison, which is implemented by the CHP library.

See the excellent explanation here: http://chplib.wordpress.com/2009/09/30/poison-concurrent-termination/

The above article incidentally goes through other solutions and explains why they're generally somewhat fragile.

sclv