如何杀死Haskell中的线程 [英] Howto kill a thread in Haskell

查看:106
本文介绍了如何杀死Haskell中的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Control.Concurrent和forkIO会导致线程处于阻塞状态(这在网络连接的windows下尤其频繁),所以即使尝试使用killThread,线程中也不会引发异常。
是否有任何其他方式强制线程死亡?



我试图用helper线程退出整个应用程序并没有任何效果在这些情况下。

Glorious Glasgow Haskell编译系统,版本6.12.1
HP 2010.1.0.0



编辑:为了清除事情,我不想终止应用程序,我宁愿杀死已经被阻塞了很长时间的线程。
然而,在SO中有很多例子,在辅助线程中使用exitWith的完整代码,并且这种方案在我所拥有的条件下不起作用。

解决方案

为了扩展我上面的评论,您不能中断阻止外部呼叫。但是,您可以使用非阻塞IO。对于Network包,这意味着对于字符串, recvLen ,对于字节串, recvFrom 。我假设你总是指定线程运行时?


Using Control.Concurrent and forkIO there are some cases that will leave the thread in a blocked state (this is especially frequent under windows with networking) so even if one try to use killThread the exception is never raised in the thread. Is there any other way to force a thread to die?

My attempt to terminate the whole application with exitFailure from a helper thread don't have any effect under these conditions.

The Glorious Glasgow Haskell Compilation System, version 6.12.1 HP 2010.1.0.0

EDIT: To clear things up, I don't want to terminate the application, I would prefer to just kill the thread that have been blocked for a very long time. However there are numerous example even here at SO with complete code using the exitWith in a helper thread and that kind of scheme don't work under the conditions I have.

解决方案

To expand on my comment above, you can't interrupt blocking foreign calls. You can, however, use nonblocking IO. In the case of the Network package, this means recvLen for strings, and recvFrom for bytestrings. I assume you're always specifying the threaded runtime as well?

这篇关于如何杀死Haskell中的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆