开发者

Graceful exit for multithreaded haskell

开发者 https://www.devze.com 2023-01-17 06:13 出处:网络
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

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. 开发者_如何学CSince 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消