简体   繁体   English

多线程haskell的优雅退出

[英]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). 每个连接都有forkIOd线程,其中一个想要退出整个程序(即./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. 所以我的第一个想法, unless done

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. 我对任何程序都没有解决方案,因此任何为任何语言提供解决方案的人都会受到赞赏,但真正的问题是如何在Haskell中完成。

The best way I know of is poison, which is implemented by the CHP library. 我所知道的最好的方法是毒药,它由CHP库实施。

See the excellent explanation here: http://chplib.wordpress.com/2009/09/30/poison-concurrent-termination/ 请参阅此处的优秀说明: 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. 上面的文章顺便通过了其他解决方案,并解释了为什么它们通常有点脆弱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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