简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM