Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graceful exit for multithreaded haskell

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.

like image 763
Masse Avatar asked May 12 '26 19:05

Masse


1 Answers

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.

like image 113
sclv Avatar answered May 15 '26 11:05

sclv